2012-01-22 19 views
3

問題是什麼?

當我使用我的表單添加文件$ _POST變量未定義。當我不添加文件時,定義$ _POST變量。

您收到了哪些錯誤?

Notice: Undefined index: bbmpin in C:\...\addpin.php on line 6 
Notice: Undefined index: usermsg in C:\...\addpin.php on line 7 

源代碼

的index.html

<form method="POST" action="addpin.php" enctype="multipart/form-data"> 
     <div> 
      <label for="bbmpin">Your BBM Pin</label> 
      <input type="text" name="bbmpin" placeholder="Enter Your BBM Pin"> 
     </div> 

     <div> 
      <label for="usermsg">Message</label> 
      <input type="text" name="usermsg" placeholder="(optional) Add a short message" maxlength="255"> 
     </div> 

     <div> 
      <label for="image">Upload Image <small>(optional)</small></label> 
      <input type="file" name="image"> 
     </div> 

     <button type="submit">Submit</button> 
</form> 

addpin.php

<?php 
session_start(); 

require_once('config/config.php'); 

$pin = $_POST['bbmpin']; 
$msg = $_POST['usermsg']; 
$ip = $_SERVER['REMOTE_ADDR']; 

print_r($_POST); 
print_r($_FILES); 
    exit; 

    ... 
?> 
+0

上傳的項目大小是多少?可能您的服務器對發佈的數據大小有限制。 –

+0

我相信這個問題可能與在ini.php中上傳大於最大文件大小的文件有關。如果我上傳一個小圖像,它工作正常。 –

+0

@pinusnegra是的我認爲這是。我只是發佈了和你一樣的東西。確保用戶沒有看到該錯誤的最佳方法是什麼?所以我可以將它們重定向到一個錯誤頁面? –

回答

1

如果帖子的大小超過了允許的最大值,全局變量$ _POST陣列將是空的。

所以你必須檢查文件上傳是否成功檢查$ _FILES數組或檢查$ _POST數組。

http://www.php.net/manual/en/features.file-upload.errors.php

如果你需要增加職位的大小限制,你應該檢查這個php.ini指令

http://www.php.net/manual/en/ini.core.php#ini.post-max-size

,也許你會需要改變它在你的網絡服務器配置(我不知道你使用哪一個)