Showing results for 
Search instead for 
Did you mean: 

PHP move_uploaded_file()


PHP move_uploaded_file()

Hello all,

I would like to have the ability for (some) users to upload small files (via form post data) onto my website to be stored in the "demos/" directory (which already exists in /home/warner/ on crofters).The file appears to successfully upload to the /tmp/ directory, at least my debugging

if(file_exists( $_FILES['file']['tmp_name']))
echo "The file really has been uploaded";

says that it has. However, I can't get the move_uploaded_file() function to work.

if(move_uploaded_file($_FILES['file']['tmp_name'], "/home/warner/demos/" . $_FILES['file']['name'] ) )
echo 'File has been stored in the demos directory';

keeps returning false. I guess it's either a permissions problem or I'm not correctly specifying the destination path properly? Should I be specifying the full path "/home/warner/demos/" or something else? Do I need to set any special permissions on the demos/ directory and/or my home directory?

In another futile debugging attempt the output of print_r($_FILES) after uploading a test file called hello.txt is:

Array ( [file] => Array ( [name] => hello.txt [type] => text/plain [tmp_name] => /tmp/phpAl8fzX [error] => 0 [size] => 5 ) )

but I don't know if that's of any help really...

Thanks a lot for any help anyone can give!

PHP move_uploaded_file()

Actually ignore this post because I got it to work. I changed the "/home/warner/demos/" string to "demos/" and the permissions on demos/ to allow others to have write access and finally the files upload!

Is there any problems with setting global write permissions on the demos/ directory? I don't want people to be able to delete files from there. Is there anything I can do other than make regular backups? Or won't this be a problem?

Cheers, Mark.