I am trying to upload multiple files to my server. If I try to upload a single file, it works fine. but if I try more than one, it will give me error code 4, although it will correctly print the name of all files. Nothing uploaded. I have the correct input type. Can anybody help me?
Choose Image: <input name="uploadedfile[]" type="file" multiple="true"/><br /><br /><br /> <input type="submit" value="Upload Image!" style="margin-left:100px;"/>
Below is the code:
$i=0; foreach($_FILES['uploadedfile']['name'] as $f) { $file['name'] = $_FILES['uploadedfile']['name'][$i]; $file['type'] = $_FILES['uploadedfile']['type'][$i]; $file['tmp_name'] = $_FILES['uploadedfile']['tmp_name'][$i]; $file['error'] = $_FILES['uploadedfile']['error'][$i]; $file['size'] = $_FILES['uploadedfile']['size'][$i]; if ($file["error"] > 0) { echo "Error Code: " . $file["error"]; } $target_path = "uploads/".basename($file["name"]); if(move_uploaded_file($file["tmp_name"], $target_path)) { echo basename($file['name'])."<br />"; echo basename($file['tmp_name'])."<br />"; echo $target_path; } else{ echo "There was an error uploading the file, please try again!"; } $i++; }
and my HTML form
<div id="album_slider"> <div style="text-align:center;margin:20px auto;font-size:27px;">Upload Image</div> <br style="clear:both;font-size:0;line-height:0;height:0;"/> <div style="width:700px;margin:auto;height:250px;text-align:left;"> <form enctype="multipart/form-data" action="uploader.php" method="POST" name="form"> Image Name: <input type="text" name="image_name" id="image_name"/><br /><br /><br /> <input type="hidden" name="a_id" id="a_id" value="<?php echo $a_id; ?>"/> Choose Image: <input name="uploadedfile[]" type="file" multiple="true"/><br /><br /><br /> <input type="submit" value="Upload Image!" style="margin-left:100px;"/> </form> </div> <br style="clear:both;font-size:0;line-height:0;height:1px;"/> </div>
pat
source share