标题说是全部。
视野中的表格:
<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");
}
}
}
我一整天都在捣乱我的屁股,所以我非常沮丧。
我收到错误是因为 if(!$ this-&gt; upload-&gt; do_upload('image')) 确实是假的。 Every.Single.Damn.Time。
我在这里做错了什么?
答案 0 :(得分:0)
错误消息是否没有给您任何帮助?看起来像Kai Qing所提到的,你需要按照EllisLab's File Upload Docs而不是URL路径使用服务器(文件系统)路径。
答案 1 :(得分:0)
这里有一些上传文件的代码
function 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");
}
答案 2 :(得分:0)
$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;
}