Nicholas Finch
Nicholas Finch

Reputation: 327

file_exists() not working on AWS ec2 server, even though works on dev server and file is where it is

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?

Upvotes: 1

Views: 502

Answers (2)

Bill Sherrick
Bill Sherrick

Reputation: 11

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;

Upvotes: 1

DudeOnRock
DudeOnRock

Reputation: 3831

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?

Upvotes: 0

Related Questions