views:

250

answers:

2

I have developed an image uploading application that uses Flash to load an image, resize the image and send the bytearray of the image data to a PHP file that outputs the resized file using the following code -

$default_path = '/uploads/temp/';
$filename = $_GET["filename"];
$destination = $default_path . $filename;
if(file_put_contents($destination, $GLOBALS["HTTP_RAW_POST_DATA"])) {
echo "The file " . basename( $_FILES[ 'Filedata' ][ 'name' ] ) . " has been uploaded;";
} else {
   echo "FILE UPLOAD FAILED";
}

This worked great when I was running it from a dedicated windows 2003 web server but now that I am trying to run this on an EC2 instance it has stopped working and I only get the "File Upload Failed" message. I can tell from Firefox's Firebug add-on that the bytearray data is being posted to the EC2 instance ok but cannot see what else would be causing the problem.

on EC2 I am running a CentOS image with PHP and Apache installed, I dont event know where to start troubleshooting this one! Please tell me what issues i need to be looking for here, any ideas?

I checked the error logs and get the following error message -

file_put_contents(/uploads/temp/abcdefg.JPG) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory

Is this to do with pointint to the wrong directory? or permissions as someone has stated below? How do I give PHP permission to write to this directory and should I use absolute path to reference the directory I want to write the image to?

cheers

A: 

I don't know if your willing to work with other's classes, but there are a few PHP EC2 classes around which may help - http://sourceforge.net/projects/php-ec2/

HipHop-opatamus
+1  A: 

Could be a permission problem, maybe the php user does not have permission to write to the specified directory.

Do you have any messages in the apache error log?

jeroen
How do I check this? I dont understand what you mean by PHP user? how do I find out what permissions this PHP user has and how do I change them?
undefined
I have updated my question
undefined
Please see my answer to another question (to avoid re-typing everything...): http://stackoverflow.com/questions/1418183/problem-getting-image-to-save/1418195#1418195
jeroen
Fantastic, that did the trick! thankyou!
undefined
You're welcome!
jeroen