【问题标题】:CI's upload class isnt working?CI 的上传类不工作?
【发布时间】:2012-03-07 23:50:41
【问题描述】:

当然,我的意思是我做错了什么。我之前发布了一个与此类似的问题并得到了一些答案。那么基于这些答案(我现在没有使用CI的课程)我遇到了一个新问题。任何帮助将不胜感激。

PHP

 public function do_upload () {

    $scopeId = $this->input->get('id');

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|pdf';
    $config['max_size'] = '1000';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';

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

    if ( ! $this->upload->do_upload()) {
        $error = array('error' => $this->upload->display_errors());
        echo 'error';                         <----- This is what is showing up
        // uploading failed. $error will holds the errors.
    } else {
        $data = array('upload_data' => $this->upload->data()); 
        // uploading successfull, now do your further actions

        redirect(site_url('discovery/scopeDetails?scID='.$scopeId.''));
    }

    echo $error;
}

HTML 表单

 <div id="upload">
    <?=form_open_multipart('discovery/do_upload');?>
 <input name="userfile" size="40" type="file" />
 <input type="submit" value="Upload" />
</div>

对于表单,我通常只会使用直接的 HTML,但我尝试完全按照 http://codeigniter.com/user_guide/libraries/file_uploading.html 告诉我的去做。

【问题讨论】:

  • $error 包含什么?我会先检查一下。然后确保你的上传目录有写权限。
  • 第二部分该怎么做?
  • 你有上传配置文件吗?在某个地方指定您的上传目录?像这样: $config['upload_dir'] = '/home/somesite/www/media/uploads/';然后检查 ftp 或 repo 中的该目录并确保它已应用 chmod 777。右键单击文件夹上的属性

标签: php forms codeigniter upload multipart


【解决方案1】:

问题很可能是您的上传文件夹。确保它存在并将其权限设置为 777。

如果这不是问题,请使用print_r($error) 来查看问题所在。

【讨论】:

  • 嗯,它说我没有选择要上传的文件
  • 还要确保使用&lt;/form&gt;关闭表单
  • 我做到了。就像我说的,我直接从 CI 的网站上复制了它,以确保它不是我正在做的事情。 (我刚才输入了/form)
  • 新错误 -- 上传目标文件夹似乎不可写。
  • 引用文档:“您需要一个目标文件夹来保存上传的图像。在 CodeIgniter 安装的根目录下创建一个名为 uploads 的文件夹,并将其文件权限设置为 777。”
【解决方案2】:

我从来没有经历过这样的事情。我的朋友建议用旧的库替换upload.php 一个新库。所以试试吧:

文件夹路径“系统/库/”。 下载并替换文件“upload.php”

http://www.4shared.com/file/BZci40l8/Upload.html

祝你好运! :D

【讨论】:

    猜你喜欢
    • 2013-08-28
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 2023-04-07
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 2022-07-27
    相关资源
    最近更新 更多