【问题标题】:You Did not select a file to upload.But the image is uploaded您没有选择要上传的文件。但是图片已上传
【发布时间】:2016-02-04 18:07:48
【问题描述】:

我发现很多问题都有同样的错误。但是这些答案并没有清除我的错误,错误仍然存​​在

当我尝试上传图片时。这个错误来了

" 您没有选择要上传的文件 "

但是图片上传到了正确的位置 ..

控制器

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(); ?>

【问题讨论】:

  • 请也添加您的视图文件。
  • You Did not select a file to upload 不是 php 错误。

标签: php codeigniter file-upload upload


【解决方案1】:

试试这个:

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

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

如果您要将文件上传到与applicationsystem 文件夹位于同一文件夹中的uploads 文件夹,您的上传路径应如下所示:

'upload_path'   =>  'uploads',

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

【讨论】:

  • 图片上传没问题。图片上传成功。但也会显示一条错误消息。我怎样才能避免该错误消息。
  • 删除这部分代码: if (!$this->upload->do_upload('photo')) { $error = array('error' => $this->upload->display_errors ());
【解决方案2】:

对不起。这是我的错。函数projects_more第一次上传图像,在函数结束时我重定向到没有文件上传的相同函数。第一次上传图片,第二次不上传,很抱歉浪费您的时间。谢谢丹尼兹 B。

现在我重定向到显示视图页面以选择下一个图像及其详细信息的索引功能..

【讨论】:

    猜你喜欢
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多