duanliaoyu8419 2017-07-31 18:25
浏览 27

如何在会话中上传多个文件?

I am trying to upload multiple images at once within sessions. In my case the user must upload the exact amount of images he stated earlier for one "position" and repeat the action for another "position" with different images againg with the correct amount. Unforunately the upload doesn't work and I don't know why. Should I use $_POST instead of $_FILES, or is the foreach method not correct? Here is the code:

HTML:

<?php

session_start();
include('php/uploadspec.php');
if(!isset($_SESSION['face'][$_SESSION['counter']])){
    header("Location: cuberender.php");
}

$speccount = 1;

?>

<div class="counter">

        <form method="post">
            <div class="form-group">
                <p>Please Choose all <?php echo  $_SESSION['quantity'] ?> photos for <?php echo $_SESSION['face'][$_SESSION['counter']] ?></p>
            </div>
            <div class="form-group">
                <input type="file" name="images[]" accept="image/*" multiple />
            </div>
            <div class="form-group">
                <input type="submit" name="Submit" value="Submit!" />
            </div>
        </form>

        <?php
        if (isset($_POST['Submit'])) {
            $imgamount=count($_POST['images']);
            if ($imgamount==$_SESSION['quantity']){
            uploadspec(session_id(), $speccount);
            $_SESSION['counter']++;
            header("Location: posteditor.php");
            }
        }
        ?>

PHP:

    function uploadspec($id, $speccount){
    foreach($_FILES["images"]["tmp_name"] as $image) {
        $target_file = $id . '/' .$_SESSION['face'][$_SESSION['counter']]. '/specimage'.$speccount;
        $speccount++;
        move_uploaded_file($image, $target_file);
    }
}

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • doufu2496 2017-07-31 18:33
    关注

    Please check php max upload limit & php max Post limit.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号