用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1522|回复: 2
收起左侧

图片上传后,打印出来没有任何数据,这是怎么回事?

[复制链接]
发表于 2015-8-5 17:31:11 | 显示全部楼层 |阅读模式
开发环境xamp,window7
点击上传后,var_dump($this->upload->data());打印出来没有任何数据,也没有提示任何错误,这是什么情况?
打印出来的结果是:


array(14) {
  ["file_name"]=>
  string(0) ""
  ["file_type"]=>
  string(0) ""
  ["file_path"]=>
  string(0) ""
  ["full_path"]=>
  string(0) ""
  ["raw_name"]=>
  string(0) ""
  ["orig_name"]=>
  string(0) ""
  ["client_name"]=>
  string(0) ""
  ["file_ext"]=>
  string(0) ""
  ["file_size"]=>
  string(0) ""
  ["is_image"]=>
  bool(false)
  ["image_width"]=>
  string(0) ""
  ["image_height"]=>
  string(0) ""
  ["image_type"]=>
  string(0) ""
  ["image_size_str"]=>
  string(0) ""
}



下面是代码,求各位大神帮帮小弟...


以下是test.php
PHP复制代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
  public function index()
        {
                $this->load->view('file.html');
        }
       
        public function upload(){
    $this->load->library('upload');
    $copnfig['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|png|jpg|jpeg';
    $this->load->library('upload',$config);
    $this->upload->do_upload('pic');
 
    var_dump($this->upload->data());
        }
}
 
?>
复制代码


以下是file.html
HTML复制代码
<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="utf-8">
        <title>上传测试</title>
</head>
<body>
 
  <form action="<?php echo site_url('test/upload');?>" method="post" enctype="multipart/form-data">
 
    <input type="file" name="pic"/>
    <input type="submit" value="上传"/>
 
  </form>
 
</body>
</html>
复制代码


发表于 2015-8-5 20:44:51 | 显示全部楼层
请仔细检查下你的代码。。
1. upload 库 load 了两次,第一次没带 config 参数,CI会以这个为准,第二次 load 没用了
2. $copnfig['upload_path'] 中的 copnfig 拼写错误!
3. 记得要检查下 './uploads/' 目录是否存在,是否有写入权限
4. 如果还有问题,可以用 $this->upload->display_errors() 把错误打印出来调试下

评分

参与人数 1威望 +2 收起 理由
Closer + 2 赞一个!

查看全部评分

 楼主| 发表于 2015-8-6 09:41:13 | 显示全部楼层
aneasystone 发表于 2015-8-5 20:44
请仔细检查下你的代码。。
1. upload 库 load 了两次,第一次没带 config 参数,CI会以这个为准,第二次 lo ...

确实是这样,我删掉了没带参数的config,现在能正常上传了,谢谢{:soso__3110130392203091378_3:}

本版积分规则