Php上传类多次上传

时间:2017-02-11 13:40:05

标签: php class upload

我尝试将多张图片上传到服务器 要做到这一点,我第一次使用class.upload.php。 课程链接:https://www.verot.net/php_class_upload.htm 我想上传多个文件只使用一个文件输入。创作者会像这样思考

   <form name="form3" enctype="multipart/form-data" method="post" action="upload.php">
        <p><input type="file" size="32" name="my_field[]" value="" /></p>
        <p><input type="file" size="32" name="my_field[]" value="" /></p>
        <p><input type="file" size="32" name="my_field[]" value="" /></p>
        <p class="button"><input type="hidden" name="action" value="multiple" />
        <input type="submit" name="Submit" value="upload" /></p>
    </form>

php side

 $files = array();
foreach ($_FILES['my_field'] as $k => $l) {
    foreach ($l as $i => $v) {
        if (!array_key_exists($i, $files))
            $files[$i] = array();
        $files[$i][$k] = $v;
    }
}

// now we can loop through $files, and feed each element to the class
foreach ($files as $file) {

    // we instanciate the class for each element of $file
    $handle = new Upload($file);

    // then we check if the file has been uploaded properly
    // in its *temporary* location in the server (often, it is /tmp)
    if ($handle->uploaded) {

        // now, we start the upload 'process'. That is, to copy the uploaded file
        // from its temporary location to the wanted location
        // It could be something like $handle->Process('/home/www/my_uploads/');
        $handle->Process($dir_dest);

        // we check if everything went OK
        if ($handle->processed) {
            // everything was fine !
            echo '<p class="result">';
            echo '  <b>File uploaded with success</b><br />';
            echo '  File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>';
            echo '   (' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';
            echo '</p>';
        } else {
            // one error occured
            echo '<p class="result">';
            echo '  <b>File not uploaded to the wanted location</b><br />';
            echo '  Error: ' . $handle->error . '';
            echo '</p>';
        }

    } else {
        // if we're here, the upload file failed for some reasons
        // i.e. the server didn't receive the file
        echo '<p class="result">';
        echo '  <b>File not uploaded on the server</b><br />';
        echo '  Error: ' . $handle->error . '';
        echo '</p>';
    }
}

但我想:

   <form name="form3" enctype="multipart/form-data" method="post" action="upload.php">
        <p><input type="file" size="32" name="my_field[]" value="" multiple /></p>
        <p class="button"><input type="hidden" name="action" value="multiple" />
        <input type="submit" name="Submit" value="upload" /></p>
    </form>

我该怎么做php方面?

0 个答案:

没有答案