I'm on mac osx10.6.8. I'm using XAMPP. I'm running all my script through firefox by typing in localhost/index.php etc. All the scripts run, and everything I've written so far works fine.
Right now, I'm able to browse my folders and upload images. It will successfully save and rename an image and store it in my htdocs folder. The problem is when I try to display the image that was just saved.
I have the following code:
<img src="file:///applications/XAMPP/xamppfiles/htdocs/Images/1921304523pvyNZ.jpg">
If I type in file:///applications/XAMPP/xamppfiles/htdocs/Images/1921304523pvyNZ.jpg in the address bar, the picture comes up. But when I try to use img src, just a broken image shows up. When I click on get info for that broken image, it gives me the exact address and even displays the image in "media preview." Why, then won't it display it in the website?
Instead of file://, use http://localhost/path/to/image/ .. then the images will be served through xampp rather than from the filesystem. I expect this is a security feature of your browser, not to mix filesystem and http-served content.
In your case, you probably want http://localhost/Images/1921304523pvyNZ.jpg
Also, make sure 'Images' does indeed have an upper case 'I'. No big deal on OSX but will be if you deploy on a Linux/UNIX server.
As Fabricio points out, you can/should reference the images relatively, and keep your web application easy to deploy. So if you are displaying http://localhost/index.php, the image path is just Images/xxxx.jpg.
I had a similar issue. I found the problem by looking at my Xampp error log. For some reason my images file permissions were very limited. -rx------... I just changed the file permission to allow all users to be able to read those files. Just a note in my opinion since I am lazy, others will probably disagree, you can give them full permission if it is on your own computer, i.e. 777. But in best practice you should only give the files the permissions that are needed for security reasons...
Since you are using a Mac you can use the chmod command to do this in terminal.
go to the file directory in terminal.
cd /Applications/XAMP/xamppfiles/htdocs/.../images/
then type in
chmod 644 yourfilename.extension
you can confirm that is was changed by using ls -l
644 should give you -rw-r--r-- This should be pretty secure.
Related
I'm facing a problem with deleting video files from folder using php unlink() function , image are deleting but when trying deleting videos it says
unlink(file_path) : permission denied.
You (running your script as either through CLI or a webserver) need write access to the directory in which the files are located. so access to the file is not enough.
Your image directory would be different and writable for webserver or cli.
chmod("your/video/dir/path",0777);
try using above code before unlink the video in your script.
Edit: Looks like you are using Windows. Unfortunately, my answer is for Unix-like operating systems (so Linux, MacOS). You could try installing Bash extension for Win8+, but still I'm not sure if this would work. However, I'm keeping my answer in case of anyone with similar problem is looking here for an answer.
Changing permissions through PHP might work in some cases, but not always, because if you don't have permissions to delete the file you might also not have permissions to change them.
The best solution is to create a directory where you will keep files to which PHP will have full access. Let's call it dirname. Once you have created a directory, change its owner and group to the one corresponding to your web server user's name (if you're using Apache, it's "www-data"), for example: chown www-data:www-data dirname.
Once you've done that, change folder's permissions. My suggestion is 744, it will assure that user who owns it will have all permissions, and everyone else will be able only to read it. To do that, execute the following command: chmod -R 777 dirname.
Now you should be able to do anything you want with the files in given directory directly from PHP.
I am trying to give someone FTP access to an NGINX /var/www/sitename folder on an Ubuntu server so they can upload development files. I have created a user 'developername' and assigned them to the 'www-data-' group. They are able to upload files, but the images (apparently only the images) are not displaying on the site. I need to SSH in and change all of the files to www-data:www-data in order for them to display correctly.
I'm trying to find a way for this user to upload files and either automatically change them to www-data:www-data or to allow NGINX to use the developername:www-data files. Do you have any ideas?
I've just been using git for a couple of years now and had tried my best to not use FTP at all anymore... This setup is a little infuriating.
Thanks for your time and any responses!
In case someone else runs into this, I first got uploaded files to automatically be in the correct group by doing this:
chmod g+s root_web_folder_name
This made all uploaded files already have the www-data group. Then I went and updated the local_umask setting in the vsftpd.conf file:
local_umask=0002
Now images are appearing when the developer uploads new files. Make sure to set permissions correctly there, I just have it lax because it's a quick test site.
I'm trying to display image on my PHP pages, but Google Chrome and Firefox on Ubuntu refuse to display the images. The same pages with the same images run pretty well in both browsers using Windows. Can any one explain to me what is happening ?
check to directory where your images are stored, make sure the permission is set to 777, or 775,
on your ubuntu terminal,
type in:
sudo chmod 777 /images_dir -R
There are 1001 reasons that could cause this.
Most probable ones:
Case problems on the file names. Many people developing systems in Windows and then porting in Linux face this problem. Remember that Linux is case sensitive. A file name a.png is different from A.png. On the other hand, windows is not case sensitive.
Permission. Your files could have a permission problem. Try to open the files from the same directory the browser is trying to retrieve the files from. If you have problems in doing this, then Firefox will have the same problem (since it runs with your credentials).
I'm experiencing a problem where I am unable to view local image files, such as a favicon .ico, .png, .svg .gif or .jpg when running apache locally. I'm using apache 2.2.26, and I am setup on a Mac using the Sites folder. Everything is running perfectly smoothly and I can even view images within my PHP and html files locally but when I type them in directly into the browsers URL field I get this error:
Forbidden
You don't have permission to access /kitten.jpg on this server.
If I try to go to a .php file or a .html file I get no such error. The page renders just fine, and like I said, if the page has image files it pulls up everything as visible. This is a minor problem since it only prevents me from seeing my favicon and from looking at images in the URL field of my browser, but it's something that I'm very curious as to why this is happening. I've checked the permissions on my files and see nothing remarkable about these particular image files. It seems that there must be something funny with the configuration files (perhaps httpd.conf? or my user.conf file?). I'm not an apache expert and any help would be appreciated. I've also tried looking this up in other posts on stackoverflow and although other people may have a similar problem as I have it never seems to be this particular problem, so I'm hesitant to move forward with those subsequent solutions. Hence my question about this specific issue. Help is appreciated, thank you.
Can you browser your DocumentRoot? like this:
cd /Library/WebServer/Documents/
if you can ls your Documents, you do this:
sudo chown -R www-default:www-default /Library/WebServer/Documents
or
sudo chmod -R 755 /Library/Webserver/Documents
if you can not ls the doucument and you get the "permission" error, you should use root and set
user and groud for yours. or set 755 Permission
I want to display image through PHP.
When I put image in /var/www/ directory then it is working fine, I am giving full path.
But when I put image in some other directory (say home) then it is not displaying.
Usually, servers have some kind of sandbox which prevent your code to access files outside of it for security reasons.
I encourage you to put all data you want your server to be able to access inside its folders (/var/www directory or subdirectories of it)
First off, you should really check your error logs as they will probably point you in the right direction.
Without more information, I'd have an educated guess that the Apache user does not have rights to the file and/or the containing directories.
You can change permissions using the chown and chmod commands in a shell.
EDIT: But don't allow access to any dir with sensitive data (e.g. your home directory) to the webserver!