Page 1 of 1

uploading images to a directory in server

Posted: Fri Nov 29, 2013 4:26 pm
by newphpcoder
Hi,

this is the program i have for uploading a file to a directory specified. i have the client program in java which asks for the path and filename to upload. the uploading works from the java end. the server side is php program that gets that file and stores it in a directory called uploads. im not able to see the image there. i get the upload success message though.
heres the code...

<?php
error_reporting(E_ALL | E_STRICT);

$filename=$_GET['fileName'];
$fileData=file_get_contents('php://input');
$fhandle=fopen("./uploads/".$filename, 'wb');
fwrite($fhandle, $fileData);
fclose($fhandle);
echo("Done uploading");
?>

my logs say theres a problem with the fwrite and fclose first parameters(have to be resource boolean...)...im not able to figure out how to debug this....any help is appreciated.thanks

Re: uploading images to a directory in server

Posted: Fri Nov 29, 2013 4:49 pm
by Celauran
fopen returns false on failure, which is why you're getting a boolean instead of a file resource. Check that the web server has write permission the the uploads directory.

Re: uploading images to a directory in server

Posted: Fri Nov 29, 2013 5:21 pm
by newphpcoder
Thats what I have been trying to find out...
i added
chmod("/uploads",0755);
to the above code and i still dont see any results...
im not sure how exactly to check if i have the write permission...can u help me with that? i see that i need to use is_writable() but having a hard time figuring out where exactly to put it in the code...
thanks a bunch!

Re: uploading images to a directory in server

Posted: Sat Nov 30, 2013 8:26 am
by Celauran
If the web server already owned the directory, then you wouldn't be running into permissions issues when trying to write to it. If it doesn't, it won't be able to change the permissions on the directory either. You'll need to do that yourself, either via the terminal or your FTP client.