多个图片上传php代码

时间:2014-10-17 09:35:31

标签: php file thumbnails image-uploading

我有一个上传图片和创建缩略图的脚本,但我想要的是上传多个图片并为每个图片创建缩略图。

我想我的问题在这里:

if(isset($_FILES['image'])) {

    $myImage = new _image;
    $myImage->uploadTo = 'uploads/';
    $res = $myImage->upload($_FILES['image']);
    if($res) {
        // RESIZE
        //$myImage->padColour = '#222222';
        $myImage->newWidth = 400;
        $myImage->newHeight = 300;
        $i = $myImage->resize();
        echo $i;
    }
} else {
    ?>
    <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
        <p>
            <input type="file" name="image" id="image" />
        </p>
        <p>
            <input type="submit" name="button" id="button" value="Submit" />
        </p>
    </form>

我知道输入应该更改为多个字段,但我需要首先创建循环。

2 个答案:

答案 0 :(得分:0)

我想我找到了你要找的东西。它由formget.com提供,并使用PHP&amp; jQuery的。

您要做的第一件事就是改变..

<input type="file" name="image" id="image" />

..成

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

image []的好处是,它们将作为数组存储和传递。

所以..

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

..会变成这样的东西:

array(0 => img1, 1 => img2, 2 => ...)

答案 1 :(得分:0)

尝试此代码....

&lt; input type =“file”name =“file []”multiple /&gt;

php代码: -

for($p=0;$p&lt;count($_FILES['file']['name']);$p++){

    echo $_FILES['file']['name'][$p];
    echo "<br />";

}   

我认为这会对你有帮助....