2017-11-18 51 views
0

我想上傳文件到服務器上。每當我提交,php全局數組$ _FILES是空的。我的文件繼續進入$ _POST。文件上傳進入POST而不是文件

 <form action="process.php" method="POST"> 
      <div class="form-group"></div> 
      <div class="form-group"> 
       <input type="file" name="uploaded_file"> 
      </div> 
      <div class="form-group"> 
       <button type="submit" class="btn btn-danger">Upload</button> 
      </div> 
     </form> 

process.php

<?php 
var_dump($_FILES['uploaded_file']); 
var_dump($_POST['uploaded_file']); 
+2

'enctype =「multipart/form-data」' –

+0

@u_mulder非常感謝您 –

+0

[File not uploading PHP]的可能重複(https://stackoverflow.com/questions/10807280/file-not-上傳-php) – Darshan

回答

5

你應該使用enctype="multipart/form-data"這樣

<form action="process.php" method="POST" enctype="multipart/form-data"> 
      <div class="form-group"></div> 
      <div class="form-group"> 
       <input type="file" name="uploaded_file"> 
      </div> 
      <div class="form-group"> 
       <button type="submit" class="btn btn-danger">Upload</button> 
      </div> 
</form> 
+0

非常感謝你 –

4

添加enctype="multipart/form-data"成HTML 像:

<!DOCTYPE html> 
<html> 
<body> 

<form action="upload.php" method="post" enctype="multipart/form-data"> 
Select image to upload: 
<input type="file" name="fileToUpload" id="fileToUpload"> 
<input type="submit" value="Upload Image" name="submit"> 
</form> 

+0

這與第一個答案有何不同? –

相關問題