首页 > 《大写的求助!!》CI上传类error:从临时空间移动文件时出现错误

《大写的求助!!》CI上传类error:从临时空间移动文件时出现错误

(PS:最新进展->我调用文件上传类库失败,也就是说我$this->load->library('upload',$cofig)这里出的问题,在这句前echo一个句子可以出来,在之后echo就不行。不知道肿么了,好心塞...)

如题:昨天上传的时候还好好的,今天使用的时候就出现了这样的情况
打印$_FILES的时候文件的数据都有 但是临时目录下根本就没有临时文件

配置如下:

$upload_cofig['upload_path'] = './uploads/sourse_message/';
$upload_cofig['allowed_types'] = 'gif|jpg|png|jpeg';
$upload_cofig['max_size'] = '100000';
$upload_cofig['max_width'] = '1024';

还有我form里也写了enctype="multipart/form-data"

这是文件上传的处理方法

public function upload_file($filename){
        $upload_cofig['upload_path'] = './uploads/sourse_message/';
        $upload_cofig['allowed_types'] = 'gif|jpg|png|jpeg';
        $upload_cofig['max_size'] = '100000';
        $upload_cofig['max_width'] = '1024';
        $upload_cofig['file_name'] = date("Y-m-d H:i:s",time()).rand(1000,9999);
        $this->load->library('upload',$upload_cofig);
        if (!file_exists($upload_cofig['upload_path'])) {
            @mkdir($upload_cofig['upload_path']);
            chmod($upload_cofig['upload_path'], 0777);
        }
        if (!$this->upload->do_upload($filename)) {
            $result = array('flag'=>0,'msg' => $this->upload->display_errors());
        }else{
            $data=$this->upload->data();
            $result = array('flag'=>1,'msg'=>substr($upload_cofig['upload_path'], 1) . $data['file_name']);
        }

        return $result;
    }

补充一下:我在本地写了相同的文件上传测试代码,结果依然只是可以打印数据,但是临时文件夹下 没有临时文件 这是什么鬼?(包括文件隐藏的什么属性我也测试过,完全行不通)


看看是不是保存文件过程出现错误


上传文件的大小?服务器post上传文件大小的限制?你这些都查清楚了?


我的代码:

/*
  *图片上传
  */
  protected function img_upload($image='')
  {
    $dirname = date( "Ymd" );
    $config['upload_path']      = '../public/images/'.$dirname.'/';
    $pathStr = $config['upload_path'];
    //文件夹不存在 则创建文件夹
    if ( !file_exists( $pathStr ) ) {
        if ( !mkdir( $pathStr , 0777 , true ) ) {
            $error = "mkdir failed";
            $code = '0';
            $res = array('0'=>$code,'1'=>$error);
            return $res;
        }
    }
    $config['allowed_types']    = 'jpg|jpeg';
    $config['file_name']        = time() . rand( 1 , 10000 );
    $config['max_size']         = 1024;
    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    if ( ! $this->upload->do_upload($image))
    {
      $error = $this->upload->display_errors();
      $code = '0';
      $res = array('0'=>$code,'1'=>$error);
      return $res;
    }else{
      $file_name = $this->upload->data('file_name');
      $url = "/public/images/".$dirname.'/'.$file_name;
      $code = '1';
      $res = array('0'=>$code,'1'=>$url);
      return $res;
    }
  }

应该有错误信息啥的吧,临时文件好像Windows能看到,linux tmp下我也找不到


1,在 Action 第一行,就先打印 $_PSOT,先确定文件是不是被提交过来,如果没提交过来,那基本就是前端的问题,否则,看 2
2,@mkdir($upload_cofig['upload_path']); 这一句其它并没有什么卵用,因为如果你创建目录失败,也不会报错,程序将继续往下进行,没有 upload_path 自然不是上传成功!
3,$this->upload->do_upload() 方法的参数是文件域的名称,然而我并不知道你那个 $filename 是什么东西!
4,打印 $this->upload->display_errors() 查看具体错误信息!

以上 4 点基本能确定问题所在!


CI中国 人好少 发布个帖子 半天没人回应 桑心

【热门文章】
【热门文章】