[英]File uploading using CodeIgniter is failing
標題說的就是全部。
視圖形式:
<tr>
<form action="<?=base_url()?>index.php/admin/product_add" method="post" enctype="multipart/form-data">
<td><input type="text" name="pid"></td>
<td><input type="text" name="name"></td>
<td><input type="file" name="image" id = "image"></td>
<td><input type="text" name="price"></td>
<td><textarea name="description"></textarea></td>
<td><input type="text" name="type"></td>
<td>
<input type="submit" value="add">
</td>
</form>
</tr>
控制器中使用的功能:
public function product_add()
{
$this->load->helper(array('form','url'));
$this->load->library('form_validation');
/*upload stuff*/
$config = array();
$config['upload_path'] = base_url()."imgs/products/";
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '9999';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$_POST['price']=str_replace(",", ".", $_POST['price']);
$this->form_validation->set_rules('pid','Product ID','required');
$this->form_validation->set_rules('name','Denumire Produs','required');
$this->form_validation->set_rules('image','Imagine','required');
$this->form_validation->set_rules('price','Pret','required');
$this->form_validation->set_rules('description','Descriere','required');
$this->form_validation->set_rules('type','Tip','required');
if ( ! $this->upload->do_upload('image'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/produse', $error);
echo "epic fail";
}
else
{
if ($this->form_validation->run() == FALSE)
{
echo "FAIL";
}
else
{
echo "asdsad";
$this->db_actions->addProduct($_POST["pid"],$_POST["name"],$_POST["image"],$_POST["price"],$_POST["description"],$_POST["type"]);
redirect(base_url()."index.php/admin/produse");
}
}
}
我整天都在搗蛋,所以我對atm感到非常沮喪。
我收到錯誤消息是因為if(!$ this-> upload-> do_upload('image'))確實為假。 每個單身的時間
我在這里做錯了什么?
錯誤消息沒有給您任何幫助嗎? 看起來像Kai Qing提到的那樣,您需要按照EllisLab的文件上傳文檔使用服務器(文件系統)路徑,而不是URL路徑。
這是我上傳文件的一些代碼
函數upload(){
$config['upload_path'] = './files/contracts-csv/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '4096';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
$this->upload->display_errors('', '');
if (!$this->upload->do_upload("image")) {
echo $this->upload->display_errors(); die();
$this->data['error'] = array('error' => $this->upload->display_errors());
//error message
} else {
//do something
}
redirect("contracts/upload_exit");
}
$config['upload_path'] = "var/www/your_app_images_path";
$config['allowed_types'] = "gif|jpg|png|jpeg";
$config['overwrite'] = false;
$config['remove_spaces'] = true;
$this->load->library('upload', $config);
檢查您的upload_path,它應該像上面一樣。
if (!$this->upload->do_upload("file_fieldName")) {
pr($this->upload->display_errors());exit;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.