PHP move_uploaded_file() fails and I don't know why
P粉111927962
P粉111927962 2024-01-29 11:04:54
0
2
442

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 tried using ftp_fput, ftp_put, move_uploaded_file for uploading, renaming, copying, anything else I could use. Nothing seems to work.

I can't understand what the problem is because move_uploaded_file only returns true or false and there is no error code.

help??

P粉111927962
P粉111927962

reply all(2)
P粉610028841

But you have to do it.

This is what error messages are for.
Do you see any error messages when something goes wrong? If not, then you must check the error log.

Add this line to the top of the code

error_reporting(E_ALL);

Also this if it is your local (non-live) server

ini_set('display_errors',1);

So you can see the error on the screen

For file uploads, you must first check $_FILES['file']['error']). If it is not 0, see the man page for the actual message.

P粉211600174

Are you sure the target directory has write permissions for world? i.e. the third number in the permission representation? Files uploaded by php are owned by and belong to the www-data

group

You can change ownership in the following ways

[sudo] chown -R www-data folder // change owner
[sudo] chown -R www-data:www-data folder // change group and owner
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template