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).
Related
I used to have a Windows OS server where i uploaded some old php web files to it. I could then access them, edit them, and view them online via my host name.
After much debating and reasoning, we had to change the OS of the server from Windows to Linux. After the change had been completed, a backup of the server was uploaded to the new Linux installation where all my old files were kept.
I could view these files online as I used to do when the server had windows OS.
The only thing I did encounter was the following:
a) I downloaded my files from the server using putty,
b) I deleted the old copy in my Linux server,
c) I then re-uploaded the same file that used to be in the server without making absolutely no change whatsoever to it, to the exact place where it was,
d) When I try to access it via its web address like I did earlier, it throws an error message saying..."The page isn't working".
I don't know much about Linux and there fore I am stuck. I don't know what the problem is. I can't understand why I can view all the files via their web address if they were placed there from the backup, but when I download them, delete their file from the server and then re-upload the exact same downloaded file to the exact place where it used to work, I get an error message.
Extra info: I connect to this Linux server from a windows OS machine using putty.
I found the problem. Since I migrated from a Windows OS server to a Linux Cent OS server, I didn't know that you had to configure the privileges of each folder in order to be accessed from the web. By default, my uploaded files where tagged by ownership of "user". The server was configured to only display files that were tagged by ownership of "root". The way I solved this was by typing the following command in the terminal.
NOTE: "You have to be in the folder where the file you are going to change ownership is."
sudo chown root:root filename.php
sudo -> Execute in admin mode
chown -> Change ownership of file to...
root:root -> ... root instead of user
filename.php -> the name of my file
Executing this corrected the error. Hope it helps someone else since I coudn't find anything related.
I have a buddypress installation on an Amazon ec2 server running default Debian linux, wordpress and buddypress installed. Users are trying to upload avatars, but they cannot be resized. This is because in the buddypress code for resizing avatars, a call to file_exists($original_file) returns false, even though I can see that the file is in exactly the directory where it's supposed to be.
This is not a problem on our development server, where uploading avatars works flawlessly. The next line of code is what causes the resizing to fail.
$original_file = '/var/www/html/wp-content/uploads/avatars/1/test-picture.png';
if(!file_exists($original_file)
return false;
Now I am ssh'd in that directory, and can see that that path is absolutely correct. I am guessing this is an issue with php permissions? To be able to access that directory and see that the file doe sin fact exist.
All files are now owned by apache:apache. I've experimented with chmod 775 and 777, but still php cannot recognize the file. Does anybody know how php can be configured on this Amazon ec2 server so that it can recognize that the file does in fact exist?
If you pasted your code above correctly, you will get a syntax error that will show up in your syslog that you are missing a closing ) in your if statement.
Your code should look like this:
$original_file = '/var/www/html/wp-content/uploads/avatars/1/test-picture.png';
if(!file_exists($original_file))
return false;
One possible cause could be case sensitivity. You state that your production server runs linux, which IS case sensitive. If your development server is a mac, you are most likely working with a non-case sensitive filesystem.
Possible solution: safe all images in all-lower-case and user lowercase directories. When calling file_exists, call strtolower on the file name.
If you are developing on a windows machine, you might be using \ as directory separators.
Possible solution:
Always use / as directory separators, since that will work on all systems.
Do you have these issues when saving to a folder that is above your document root?
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.
I am building a web page with Apache2.2, PHP5.2.2 on a Windows XP computer in a localhost configuration. I'm developing app/pages/submitProcessor.php to validate photo uploads from users. It validates file existance, size, mime type, drops unwanted characters, assigns a new file name, and uses move_uploaded_file() to store the file in app/uploads. I read in PHP - Question about uploading & uploaded image file that this photo storage file should be write only from app/pages/submitProcessor.php and it would be nice if it were read only from code within app/pages.
I've read a lot of info, and being pretty new to this, I still don't understand how to set read/write permissions in Windows XP in something resembling my configuration. I'm completely confused by 777, 775, 755, php.ini vs httpd.config and linux vs Windows. I'm also not comfortable with command line stuff, and would prefer to edit the appropriate file, if that is possible. How do I configure Apache so any file in app/uploads will not be executable, will write only from app/pages/submitProcessor.php, and read from app/pages/display or others in app/pages . . . or at least I'd like to get close to that. Not executable in the app/upload directory is pretty important to me.
If you are running Apache as a Service (the default setup for stand-alone & WAMP Apache installations), then that Apache Service is running under Windows' LocalSystem account.
This Windows account already has full read and write ('777') permissions on most local paths.
So when you read instructions to chmod 777 this, chmod 755 that, etc, ... you can ignore those parts of the instructions. Apache already can read-from and writeout-to those directories (unless it's a UNC path of a networked drive).
Setting File Permissions with chmod on Windows for Apache and PHP
I'm not 100% positive if that was the account on Windows XP (it is on Vista and up), but the behavior was the same.
In Windows, access to directories/folders is set by right clicking the directory, and reading through the selections provided by the various tabs to set access and specific uses of the directory. Its not as fine-grained as CHMOD, but it was good enough for my purposes at the moment.
I've got a project that I am setting up file uploads for. The project is in Zend, but I am using PHP's $_FILES array and move_uploaded_file to save the files. This was working perfectly on my Windows Vista computer but won't save the file on Windows 7.
It creates a new folder for every upload no problem, but won't save the file and gives no error message. It is the same exact code as the other computer (grabbed from source control) and both are using PHP 5 with WAMP server. Any ideas why the Windows 7 computer won't save? I even added Full Control to 'Everyone' for the uploads folders.
In Windows 7:
Go to this location -> C:\Windows\Temp
Windows will ask permission- > press go or confirm or yes
then try again to upload files
finish
if your saving the files in the system drive, you might have a problem due to its security.. try to transfer your WAMP and PHP in other local drives. but if you insist to have it in your system file. just try to work around with its security.. Good Luck!
When you create the folder you want to move it to, are you setting the permissions in php? When I switched to windows 7 I had the same problem and setting the permissions solved it for me.
mkdir("/path/to/your/dir", 0777);
I read that chmod is ignore by windows on the php.net > mode reference. I was not able to mkdir on windows 7 by using mkdir /path/to/directory or path\to\directory\. I also tried editing the permissions for the parent (root?) directory I was using for the new folder. No solutions found here, yet. The folder reverts to read-only after unchecking the box on the folder settings though so maybe that is part of it