【问题标题】:Codeigniter File upload not uploading [closed]Codeigniter文件上传未上传[关闭]
【发布时间】:2015-01-24 22:04:11
【问题描述】:

我在将文件上传到“临时”文件夹时遇到问题。 这是上传te文件的mij代码

//GET RANDOM STRING FOR TEMP FOLDER ATTACHMENT
    $randompath = $this->generateRandomString(20);
    $config['upload_path'] = "./include/upload/temps/$randompath/";
    $config['allowed_types'] = 'gif|jpg|png|pdf|tiff';
    $config['max_size'] = '2048';
    $config['max_width'] = '0';
    $config['max_height'] = '0';
    $config['remove_spaces'] = true;

    $fullpath = $config['upload_path'] . $_FILES['attachment']['name'];

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

    if ( ! $this->upload->do_upload('attachment'))
    {
        $cookie = array(
            'name'   => 'Attachment',
            'value'  => $fullpath
        );

        $this->input->set_cookie($cookie);
        //return $fullpath;
        return true;
    }
    else
    {
        return false;
    }

我希望任何人都可以帮助我解决这个问题。 文件夹权限为 755 下面的代码也没有设置cookie

【问题讨论】:

  • 什么问题?它会产生任何错误日志条目吗?

标签: php codeigniter file-upload


【解决方案1】:

上传文件夹chmod777并做一个固定位置示例

$config['upload_path'] = './upload/temp/'

为了能够获取上传的数据,例如。

$variable = $this->upload->data(); 在表单的成功部分。

那你可以这样做$variable['full_path']

http://www.codeigniter.com/user_guide/libraries

我还看到你没有 $this->upload->initialize($config); 你需要让配置工作,如用户指南中所述。

$file_upload = $this->upload->data();

$fullpath = $file_upload['full_path']
$filename = $file_upload['file_name']

$fullpath = $file_upload['full_path'] 也是如此

$config['upload_path'] = "./include/upload/temps";
$config['allowed_types'] = 'gif|jpg|png|pdf|tiff';
$config['max_size'] = '2048';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['remove_spaces'] = true;

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

if ($this->upload->do_upload('attachment') == TRUE) {

    $file_upload = $this->upload->data();

    $cookie = array(
        'name'   => 'Attachment',
        'value'  => $file_upload['full_path']
    );

    $this->input->set_cookie($cookie);

    $this->load->view('upload_success');

} else {

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

    $this->load->view('upload_form', $error);

}

【讨论】:

  • 感谢您的帮助,我发现随机文件夹从未被创建,因此文件从来没有现有目录,感谢您的尝试
猜你喜欢
  • 1970-01-01
  • 2013-08-24
  • 1970-01-01
  • 2013-02-12
  • 2012-10-07
  • 2015-12-26
  • 2011-10-19
  • 2011-11-06
相关资源
最近更新 更多