0

this is html code:

 <form id="upload" action="upload.php" method="POST" enctype="multipart/form-data">
 <fieldset>
 <legend>html upload</legend>
 <input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="300000" />
 <div>
 <label for="fileselect">select file</label>
 <input type="file" id="fileselect" name="fileselect[]" multiple="multiple" />
 </div>
 <div >
 <button type="submit">upload</button>
 </div>
 </fieldset>
 </form>

code of upload.php:

 $myFile = $_FILES['fileselect'];
 $fileCount = count($myFile["name"]);
 for ($i = 0; $i < $fileCount; $i++) {
 $target_dir = "uploads/";
 $target_file = $target_dir . basename( $myFile["name"][$i]);
 // echo $myFile["tmp_name"][$i];
 if (move_uploaded_file( $myFile["tmp_name"][$i], $target_file)) {
 echo "The file ". basename( $myFile["name"][$i]). " has been uploaded.";
 } else {
 echo "can not move";
 }
 }

If i upload file type is Image or MP4, they upload ok.

i try var_dump : upload a image.

array(1) { ["fileselect"]=> array(5) { ["name"]=> array(1) { [0]=> string(10) "header.png" } ["type"]=> array(1) { [0]=> string(9) "image/png" } ["tmp_name"]=> array(1) { [0]=> string(24) "C:\xampp\tmp\phpED23.tmp" } ["error"]=> array(1) { [0]=> int(0) } ["size"]=> array(1) { [0]=> int(32416) } } } The file header.png has been uploaded.

Upload a pdf:

array(1) { ["fileselect"]=> array(5) { ["name"]=> array(1) { [0]=> string(15) "Untitled-12.pdf" } ["type"]=> array(1) { [0]=> string(0) "" } ["tmp_name"]=> array(1) { [0]=> string(0) "" } ["error"]=> array(1) { [0]=> int(2) } ["size"]=> array(1) { [0]=> int(0) } } } can not move

But i can't upload file pdf.

Why can't upload file pdf?

asked May 16, 2017 at 11:32
7
  • What actually is the error message are you getting? Commented May 16, 2017 at 11:35
  • any errors? and does the pdf file is greater than MAX_FILE_SIZE value ? Commented May 16, 2017 at 11:35
  • error: echo "khong the move"; Commented May 16, 2017 at 11:36
  • size of file pdf only has 300kb Commented May 16, 2017 at 11:37
  • I suggest you ALWAYS check $myFile["name"][$i]['error'] whenever you do an upload. It will normally show you what the problem is or at least lead you to the solution Commented May 16, 2017 at 12:36

1 Answer 1

1

First of all there is an issue, check the following line:

<input type="file" id="fileselect" name="fileselect" multiple="multiple" />

input file with multiple selection must have its name as an array so that it can hold multiple files name like:

<input type="file" id="fileselect" name="fileselect[]" multiple="multiple" />

Without this you cannot iterate over all the files.

answered May 16, 2017 at 11:38
Sign up to request clarification or add additional context in comments.

2 Comments

thank,i miss when post question. but that is not my problem
Upload a pdf : array(1) { ["fileselect"]=> array(5) { ["name"]=> array(1) { [0]=> string(15) "Untitled-12.pdf" } ["type"]=> array(1) { [0]=> string(0) "" } ["tmp_name"]=> array(1) { [0]=> string(0) "" } ["error"]=> array(1) { [0]=> int(2) } ["size"]=> array(1) { [0]=> int(0) } } } can not move

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.