我在使用codeigniter POST多部分表單時遇到了麻煩。表單包含文本字段和8個文件上傳字段。問題是,文件成功上傳,沒有錯誤,但文本字段在我的控制器中爲空。Code Ingiter POST數據爲空
我試着print_r POST數據並得到一個空數組。但有時當我使用谷歌瀏覽器時,它沒有任何問題。
任何解決方案?
我在使用codeigniter POST多部分表單時遇到了麻煩。表單包含文本字段和8個文件上傳字段。問題是,文件成功上傳,沒有錯誤,但文本字段在我的控制器中爲空。Code Ingiter POST數據爲空
我試着print_r POST數據並得到一個空數組。但有時當我使用谷歌瀏覽器時,它沒有任何問題。
任何解決方案?
<form name="form" action="some action page.php" method="post" enctype="multipart/form-data">
<input type="text" name="inputfieldvalue" value="Input Field">
<input type="file" name="uploadedfile" id="uploadedfile">
<input type="submit" value="Submit" >
</form>
//假設您的形式是這樣的正上方,然後檢查文本字段值
<?php echo $_POST['inputfieldvalue']; ?>
//通過name屬性無論你已經給$ _ POST [您的姓名字段值。像這樣
完整的例子應該工作。
您的表單目標行動功能my_form
在My_controller
控制器。爲了避免與名嘗試輸入WTF
<form name="form" action="my_controller/my_form" method="post" enctype="multipart/form-data">
<input type="text" name="WTF" value="Input Field">
<input type="submit" value="Submit" >
</form>
在My_controller.php
文件(CI控制器文件夾)的cotroller行動應該是樂此
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class My_controller extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index(){
/* do something for page my_controller if you want */
} // end of index
function my_form() { // = my_controller/my_form
$here_is_it = $this->input->post('WTF'); // call value of input with name WTF
/* test it */
print_r($here_is_it);
}
外,以確保一切也沒關係。您可以在Codeigniter中啓用自動加載功能。 follow this tutorial
我只是檢查了一會兒,問題是不是在PHP或我的HTML格式的代碼。但問題是在我的php.ini配置。通過增加上傳文件大小來解決問題。我之前只是感到困惑,因爲這種形式有時運作良好,有時會給出一個空值。
在此先感謝
很難猜到,也許你忘了設置名稱屬性字段。編輯問題和發佈表單以及控制器代碼。 – Tpojka