2017-07-31 70 views
-1

我想在會話中一次上傳多個圖像。在我的情況下,用戶必須上傳他爲一個「位置」提供的確切數量的圖像,並以不同的圖像重複該動作以獲得正確的數量。不幸的是,上傳不起作用,我不知道爲什麼。我應該用$_POST而不是$_FILES,還是foreach方法不正確?下面是代碼:如何在會話中上傳多個文件?

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); 
    } 
} 

提前感謝!

+0

*「我應該使用$ _POST而不是$ _FILES的,或者是在foreach方法不正確嗎?」 * - '$ _FILES' ,並且在手冊中有一個示例,您可以基於http://php.net/manual/en/features.file-upload.post-method.php –

+0

如果您使用的任何內容失敗,請使用錯誤報告http://php.net/manual/en/function.error-reporting.php –

+0

'if(!isset($ _ SESSION ['face'] [$ _ SESSION ['counter']]))'that that could be順便讓你在這裏順便說一句。 –

回答

0

請檢查php最大上傳限制& php max限制後。

0

入住在php.ini文件更新最大上傳大小和郵政業最大規模