我有一種情況,用戶上傳他/她的旅行照片。它們保存在一個文件夾中,也應該在數據庫中。情況是:我的代碼在本地主機和許多其他服務器上運行良好,但不在我想要的服務器上運行。雖然它成功上傳文件,但是查詢並未執行,應該保存數據庫中的文件路徑。我從一個多星期就陷入這個問題。相同的代碼適用於其他地方。這裏是我的控制器:Codeigniter圖像上傳無法在現場服務器上工作
public function trip_photos(){
$this->load->model('UserModel');
$this->load->model('CommentModel');
$this->load->library('session');
print_r($_FILES);
$logged_session = $this->session->userdata('login');
if($logged_session == 1) {
$this->load->model('TripModel');
$this->load->model('UserActivityModel');
$uid = $this->session->userdata('uid');
$tid = $this->input->post('tid');
foreach($_FILES as $key => $image_upload){
$upload = self::upload_trip_photo($key);
if($upload['status']){
$this->TripModel->add_trip_photo($uid, $tid, $upload['file']);
}
}
$this->UserctivityModel->add_user_photo($uid, $tid);
}else{
redirect('/');
}
}
private function upload_trip_photo($image){
$msg = '';
$config['upload_path'] = './assets/images/trip/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2048;
$config['file_name'] = parent::getGUID();
$this->load->library('upload', $config);
if ($this->upload->do_upload($image))
{
$data = $this->upload->data();
$resize['image_library'] = 'gd2';
$resize['source_image'] = "./assets/images/trip/" . $data['file_name'];
$resize['create_thumb'] = TRUE;
$resize['maintain_ratio'] = TRUE;
$resize['width'] = 222;
$resize['thumb_marker'] = '';
$resize['new_image'] = "./assets/images/trip/thumbnails/" . $data['file_name'];
$this->image_lib->resize();
$this->image_lib->clear();
$this->image_lib->initialize($resize);
if($this->image_lib->resize()){
$status = true;
$msg = $data['file_name'];
}else{
$status = false;
}
}
else
{
$status = false;
}
@unlink($_FILES[$image]);
return array('status' => $status, 'file' => $msg);
}
當我啓用CI_Profiler,它說,只有2個3查詢我希望它的工作在服務器上執行。但同一個分析器建議在本地主機或其他服務器上執行3個查詢中的3個。它很混亂。 請注意,我已經檢查了以下內容:
- 文件上傳:在
- upload_raw_post_data:在
- SELinux的權限:禁用(我的是CentOS的)
- 文件權限:777
- PHP memory_limit:128 MB
- max_size:8 MB
- var_dump,print_r,echo全部不工作或顯示任何信息控制器。 莫名其妙地,在上面的代碼中:
$upload = self::upload_trip_photo($key);
沒有將它返回到它需要的文件路徑。任何人都可以幫忙嗎? @DFriend
修訂原來,在本地主機身在何處其工作,該陣列由函數upload_trip_photo回到$上傳變量其他服務器:
Array ([image0] => Array ([name] => maintour3.jpg [type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php2539.tmp [error] => 0 [size] => 200491))
array(2) { ["status"]=> bool(true) ["file"]=> string(36)
"E3965DFC8B265CEFF522A1EC43B33E34.jpg" }
而在服務器裏它不工作,只返回此數組:
Array ([image0] => Array ([name] => mg7.jpg [type] => image/jpeg
[tmp_name] => /tmp/phpNcCnX0 [error] => 0 [size] => 28460))
這意味着在upload_trip_photo()函數這一說法: [R eturn數組('status'=> $ status,'file'=> $ msg);
未返回請求的數組,其中包含文件名和狀態。爲什麼?我完全無能爲力。
幫助請!
圖像上傳到特定的文件夾或不是? –
Hi @DeepParekh。圖像上傳到特定的文件夾中,是的。特定的文件夾是root:/ assets/images/trip/ – Zafar
ok thj jst該圖像的路徑或名稱未插入數據庫中? –