uploading images to a directory in server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
newphpcoder
Forum Newbie
Posts: 2
Joined: Fri Nov 29, 2013 4:18 pm

uploading images to a directory in server

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: uploading images to a directory in server

Post 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.
newphpcoder
Forum Newbie
Posts: 2
Joined: Fri Nov 29, 2013 4:18 pm

Re: uploading images to a directory in server

Post 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!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: uploading images to a directory in server

Post 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.
Post Reply