-4

trying to upload multiple files Move_uploaded_file not working. file permission user#777

$file = $_FILES['photo'];
$count = count($file['name']);
for($a = 0 ; $a<$count ; $a++)
{
echo  $_FILES['photo']['name'][$a];
$target_dir =  preg_replace('/\s+/', 
'',$name.'_'.basename($_FILES['photo']['name'][$a]));
$target_file = "../upload/".$target_dir;
echo $target_file;  
    if(move_uploaded_file($_FILES['photo']["name"][$a], $target_file))
    {
        echo 'yes';
    }
    else
    {
        echo 'no';
    }
}
anonymous
  • 1
  • 1

1 Answers1

0

You maybe pointing to the wrong path. Make it complete by using $_SERVER['DOCUMENT_ROOT'].

This:

$target_file = "../upload/".$target_dir;

to:

$target_file =  $_SERVER['DOCUMENT_ROOT']."/upload/".$target_dir;

The source file should be 'tmp_name' one, not the 'name'.

From:

if(move_uploaded_file($_FILES['photo']["name"][$a], $target_file)){

To:

if(move_uploaded_file($_FILES['photo']["tmp_name"][$a], $target_file)){

If the above changes still don't fix it:

Check your php.ini

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =

; Maximum allowed size for uploaded files.
upload_max_filesize = 50M


; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20
Karlo Kokkak
  • 3,674
  • 4
  • 18
  • 33