2017-08-08 75 views
0

我用這上傳腳本http://www.dropzonejs.com上傳的文件在for循環

上傳PHP的部分是:

foreach($_POST["id"] as $key=>$value) 
{ 
    $id = trim(mysqli_real_escape_string($mysqli, $value)); 
    $pre_set = trim(mysqli_real_escape_string($mysqli, $_POST['pre_set'][$key])); 
    $keep_filename = trim(mysqli_real_escape_string($mysqli, $_POST['keep_filename'][$key])); 

    $ds   = DIRECTORY_SEPARATOR; 

    $storeFolder = '../uploads'; 

    if (!empty($_FILES)) 
    { 

     $tempFile = $_FILES['file']['tmp_name']; 

     $targetPath = dirname(__FILE__) . $ds. $storeFolder . $ds; 

     if($keep_filename == 'yes') 
     { 
      $targetFile = $targetPath. $pre_set.'_'.$id.'_'.$_FILES['file']['name']; 
     } 
     else 
     { 
      $targetFile = $targetPath. $pre_set.'_'.$id.'.'.pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); 
     } 

     move_uploaded_file($tempFile,$targetFile); 

    } 
} 

當使用這種具有如圖所示的文件低於標準形式是正確上傳並改名:

<form action="includes/upload.php" class="dropzone"> 

<input type="hidden" class="form-control" id="id[]" name="id[]" value="'.$row['id'].'"> 
<input type="hidden" class="form-control" id="pre_set[]" name="pre_set[]" value="logo"> 
<input type="hidden" class="form-control" id="keep_filename[]" name="keep_filename[]" value="no"> 

</form> 

但是,當使用for循環的情況下,圖片顯示在上傳窗口中,但文件未上傳。 我沒有得到任何錯誤(或者沒有使用正確的參數看到它)

while($row = mysqli_fetch_array($res)) 
{ $i++; 
    echo' 

<div class="container"> 

<form action="includes/upload.php"> 

    <div class="form-group col-md-3">'; 
     if($i == 1) { echo '<label>Voeg foto toe</label>'; } echo' 
     <div class="dropzone dropzone_small" id="myId'.$i.'"> 
      <div class="fallback"> 
       <input type="hidden" class="form-control" id="id[]" name="id[]" value="xxxx"> 
       <input type="hidden" class="form-control" id="pre_set[]" name="pre_set[]" value="toolbox_"> 
       <input type="hidden" class="form-control" id="keep_filename[]" name="keep_filename[]" value="yes"> 
      </div> 
     </div> 
    </div> 
</form>'; 
} 

任何建議更改代碼得到這個工作?

非常感謝幫助。

+0

開始與'enctype'屬性,我想。 –

+0

它是http://www.dropzonejs.com的一部分,請參閱我的第一個沒有建議編輯的示例。 – Muiter

+0

你想上傳多個文件嗎? –

回答

-1

您必須

<form action="includes/upload.php"> method="post" enctype="multipart/form-data"> 

//你的表單開始表單屬性在這裏

</form> 
+0

它是http://www.dropzonejs.com的一部分,看到我的第一個例子,沒有你的建議編輯工作。 – Muiter