简体   繁体   中英

Upload folder files and save to different directories

I'm using this code to upload folder files.

    <form action="file_transfer.php" method="post" enctype="multipart/form-data" name="form1">
        <input type="file" name="file_input[]" id="file_input" multiple="" webkitdirectory="">
        <input type='submit' class='btn' id='btn_upload_file' value='UPLOAD' data-loading-text='loading....'/>
    </form>

And file_transfer.php

$uploads_dir = 'C:/xampp/htdocs/awoc_inspection/Images/IMAGES/';
for($i = 0; $i < sizeof($_FILES['file_input']['name']); $i++){

$tmp_name = $_FILES['file_input']['tmp_name'][$i];
$name = $_FILES['file_input']['name'][$i];

echo $_FILES['file_input']['tmp_name'][$i];
echo $_FILES['file_input']['name'][$i];

echo"<br/>";
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}

It does not show any error but when I go to C:/xampp/htdocs/awoc_inspection/Images/IMAGES/ folder there is no image. I don't know why this code can't move uploaded folder files please help me :(

It doesnt print error cause you didnt ask it to do:

echo $_FILES["file"]["error"][$i];

The problem might be that your directory doesnt have good permission try chmod 775 or 777 Also do:

echo $result = move_uploaded_file($tmp_name, "$uploads_dir/$name");

to check whether $result is true or false, if false then moving file wasnt done

Try to change the for condition with:

for($i = 0; $i < sizeof($_FILES['file_input']); $i++) {
   ...

I've overcome own my problem :) .. thank's everyone for your answers ... the only problem why I can't upload pictures it is because the picture that I'm trying to upload is 3mb above and the maximum upload file_size in php is 2mb .

I've changed php.ini to

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

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 50M

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM