PHP move_uploaded_file () FAILS and I don't know why

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 to download from ftp_fput, ftp_put, move_uploaded_file, rename, copy and all that I can put in my hands. nothing works.

I cannot understand what the problem is, because move_uploaded_file returns only true or false and there is no error code.

help??

+5
source share
7 answers

Are you sure that the destination directory has write permissions for world, i.e. third number in permission view? Files uploaded by php belong and belong to the groupwww-data

You can change the ownership of

[sudo] chown -R www-data folder // change owner
[sudo] chown -R www-data:www-data folder // change group and owner
+10
source

I do not know why

But you have to.

.
, - ? , .

error_reporting(E_ALL);

, ( )

ini_set('display_errors',1);

$_FILES['file']['error']). 0, .

+11

move_uploaded_file, $_ FILES ['filename'] ['error'].

, . move_uploaded_file , .

+3

? , , , , . var "upload_max_filesize" php.ini .

+2

. , move_uploaded_file() 0.

+1

error_reporting?

php-config, .

0

. :

move_uploaded_file () is safe mode and open_basedir. However, restrictions are placed only on the destination path to allow the movement of uploaded files in which the file name may conflict with such restrictions. move_uploaded_file () provides security for this operation, allowing you to only move files downloaded through PHP.

These settings may cause the download to fail if you try to move the file outside the base directory of your website, for example.

0
source

All Articles