您没有选择一个文件上传。但图像上传

问题描述:

我发现这么多问题都有同样的错误。但这些答案并没有清除我的错误,仍然错误仍然您没有选择一个文件上传。但图像上传

当我尝试上传图像。这个错误出现

没有选择要上传的文件

图像在正确的位置上传..

控制器

class image extends CI_Controller { 

    function __construct() { 
    parent::__construct(); 

    $this->load->helper(array('form', 'url')); 

    $this->load->library('session'); 

    $this->load->library('layout'); 

    $this->load->model('admin_m'); 

    $this->load->library('upload'); 

    } 

    function projects_more() { 

    $config['upload_path'] = './uploads/'; 

    $config['allowed_types'] = 'gif|jpg|png'; 

    $config['max_size'] = '100000'; 

    $config['max_width'] = '102400'; 

    $config['max_height'] = '76800'; 


    $this->load->library('upload', $config); 

    $this->upload->initialize($config); 

    if (!$this->upload->do_upload('photo')) { 

     $error = array('error' => $this->upload->display_errors()); 

     $this->layout->view('home_page', $error); 

    } else { 

     $data = array('upload_data' => $this->upload->data()); 
     $data1 = $this->upload->data(); 
     $image = $data1['file_name']; 
     $project = $this->input->post('project'); 


     $content= $this->input->post('content'); 

     $this->admin_m->projects_more($image,$project,$content); 
     redirect('image/projects_more'); 

    } 
    } 
} 

我的看法页面

projects1.php

<?php echo form_open_multipart('image/projects_more'); ?> 

<table> 

<tr> 

<td><input type="file" name="photo" id="photo" size="20"></td> 

</tr> 

</table> 

<input type="submit" name="submit" value="Submit"> 

<?php echo form_close(); ?> 
+1

请将您的视图文件了。 –

+3

'你没有选择一个文件上传'不是一个PHP错误。 –

对不起。这是我的错误。函数projects_more第一次上传图像,并在函数结束时重定向到没有要上传文件的相同函数。第一次它上传图像,第二次它不会。因为浪费你的时间。感谢丹尼斯B.

现在我重定向到索引功能,显示视图页面,选择下一个图像及其细节..

试试这个:

$this -> load -> library('upload'); 

$config = array 
(
'upload_path' => 'yourUploadPath', 
'allowed_types' => 'png|jpg|gif', 
); 
$this -> upload -> initialize($config); 
$this -> upload -> do_upload('photo'); 

如果你想将文件上传到uploads文件夹是有同一文件夹applicationsystem文件夹,你的上传路径应该是这样的:

'upload_path' => 'uploads', 

顺便说一句,您不需要逐页加载库和帮助程序,您可以使用autoload.php文件夹下的application/config文件夹。

+0

图像上传没有问题。图像上传成功。但是还显示一条错误消息。我如何避免该错误消息。 –

+0

删除这部分代码: if(!$ this-> upload-> do_upload('photo')){ $ error = array('error'=> $ this-> upload-> display_errors()) ; –