PHP上传器仅上传1个文件

时间:2013-08-08 14:22:39

标签: php html file-upload

我的页面中有一个上传器,设计可以在iPad上工作,有8个上传框。

当我在上传器中上传图片时,只保存一个文件。

如何保存所有上传的图片?

  • 文件夹设置为777。

The Page

PHP:

<?
if ( isset( $_POST['submit'] ) ){
    foreach ($_FILES['file']['name'] as $_key => $_value){
        if($_FILES['file']['size'][$_key] !==0){
            $randomizer = rand(0000000, 9999999);
    $f=$randomizer.$_FILES['file']['name'][$_key];
    echo $f;
    echo "<br>";
    $t=$_FILES['file']['tmp_name'][$_key];
    echo $t;
    echo "<br>";

    //echo $_FILES['file']['size'][$_key]."<br />";
    $file_mb = round(($_FILES["file"]["size"][$_key] / 1048576), 2);
    echo "Size: " . $file_mb . " Mb<br />";
    echo $_FILES['file']['type'][$_key]."<br />";
    if( file_exists($t) ){ move_uploaded_file($t, 'upload/' . $f); }
    //move_uploaded_file($_FILES['file']['tmp_name'][$_key], "upload"/$_FILES['file']['name'][$_key]);
    echo "ok file";
    echo "<br>";
}
    }
}
?>
<form id="main_form" action="" method="POST" enctype="multipart/form-data">
<?  for($i = 0; $i < 9; $i++) {
    echo "<input type=\"file\" name=\"file[]\" /> <br>";
    }
    ?>

    <input  type="submit" name="submit" value="send">
</form>

HTML:

<input type="file" name="image1" /><br /> <br /> <br /> 
<input type="file" name="image2" /><br /> <br /> <br /> 
<input type="file" name="image3" /><br /> <br /> <br /> 
<input type="file" name="image4" /><br /> <br /> <br /> 
<input type="file" name="image5" /><br /> <br /> <br /> 
<input type="file" name="image6" /><br /> <br /> <br /> 
<input type="file" name="image7" /><br /> <br /> <br /> 
<input type="file" name="image8" /><br /> <br /> <br />

0 个答案:

没有答案