2012-08-02 38 views
0

我無法成功上傳圖像/文件到我的服務器。 php如下:通過PHP上傳圖像並返回空數組

//This is the directory where images will be saved 
$uploadDir = "./"; 
$uploadFile = $uploadDir . basename($_FILES['photo']['name']); 

//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $uploadFile)){ 
    echo "The file has been uploaded successfully."; 
} else { 
    print_r($_FILES); 
} 

我選擇了這個腳本所在的目錄,以確保在我上傳到最終目錄之前的功能。我想上傳照片,稍後會檢查文件擴展名 - 但現在我至少需要上傳功能才能工作。我得到一個空數組返回。

的形式如下:

<form id="imageUploadForm" name="imageForm" enctype="multipart/form-data" action="imageController.php"> 
<label for="photo" class="blogLabel">Upload an Image</label> 
<input type="file" name="photo" id="imageUpload"> 
<input type="submit" name="submit" id="imageSubmit" class="btn btn-primary" value="Upload"> 
</form> 
+0

窺探到web服務器日誌。你不能用盡最大上傳大小嗎? – spacediver 2012-08-02 21:03:36

+0

上傳文件夾是否具有寫入文件的適當權限? – j08691 2012-08-02 21:04:52

+0

位於imageController.php的頂部。把'print_r($ _ FILES); print_r($ _ POST); exit()' – 2012-08-02 21:06:06

回答

0

你忘了最重要的東西約形式 - method

如果沒有設置方法,則默認爲get

你想要post

method="post"添加到您的表單中。

+0

@Dagon哈!我一直想念那些新的評論大聲笑。這是在這裏...我的網絡waaaaay太慢.... – Neal 2012-08-02 21:14:01

+0

哈哈對不起 - 這是我的錯。 – mdance 2012-08-02 21:14:06

+0

@mdance啊,但它解決了你的空陣列問題^ _ ^ – Neal 2012-08-02 21:14:57