this is my code:
$uploaddir = '/temp/';
$uploadfile = $uploaddir.basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
send_OK();
else
send_error("ERROR - uploading file");
i have tried to upload with ftp_fput, ftp_put, move_uploaded_file, rename, copy and anything i can put my hands on. nothing seems to work.
i can't understand what is the problem since move_uploaded_file returns only true or false and no error code.
help??
But you have to.
That's what error messages are for.
Do you see any error message when something goes wrong? If not, then you have to check error logs.
Add this line at the top of your code
and this one, if it's your local (not live) server
so you'll be able to see errors onscreen
For the file uploads you have to check
$_FILES['file']['error'])
first. it it's not0
, refer to the manual page for the actual message.I experienced a similar problem when using move_uploaded_file which would fail to upload particular files with an $_FILES['filename']['error'] code of 0.
It turns out that the name of the file needs to be unique in relation to the destination directory. move_uploaded_file does not know how to handle identical files names.
Did you try to activate error_reporting?
You should check your php-config if file uploads are allowed.
Are you sure that the target directory has write permissions for
world
?ie,the third number in permission representation? The files uploaded by php are owned by and comes under the groupwww-data
You can change the ownership by
This caught me out too. Be aware of:
These settings can cause the upload to fail if you try to move the file outside of your website base directory for example.
In addition to permissions, be sure to check that there is disk space available on your server. If not, move_uploaded_file() will fail with error 0.