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