《大寫的求助!!》CI上傳類error:從臨時空間移動檔案時出現錯誤

來源:互聯網
上載者:User
關鍵字 php ci
( 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;    }

補充一下:我在本地寫了相同的檔案上傳測試代碼,結果依然只是可以列印資料,但是臨時檔案夾下 沒有臨時檔案 這是什麼鬼?(包括檔案隱藏的什麼屬性我也測試過,完全行不通)

回複內容:

(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;    }

補充一下:我在本地寫了相同的檔案上傳測試代碼,結果依然只是可以列印資料,但是臨時檔案夾下 沒有臨時檔案 這是什麼鬼?(包括檔案隱藏的什麼屬性我也測試過,完全行不通)

CI中國 人好少 發布個文章 半天沒人回應 桑心

上傳檔案的大小?伺服器post上傳檔案大小的限制?你這些都查清楚了?

應該有錯誤資訊啥的吧,臨時檔案好像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 點基本能確定問題所在!

My Code:

/*  *圖片上傳  */  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;    }  }
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.