0

我有一种情况,用户上传他/她的旅行照片。它们保存在一个文件夹中,也应该在数据库中。情况是:我的代码在本地主机和许多其他服务器上运行良好,但不在我想要的服务器上运行。虽然它成功上传文件,但是查询并未执行,应该保存数据库中的文件路径。我从一个多星期就陷入这个问题。相同的代码适用于其他地方。这里是我的控制器: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个。它很混乱。 请注意,我已经检查了以下内容:

  1. 文件上传:在
  2. upload_raw_post_data:在
  3. SELinux的权限:禁用(我的是CentOS的)
  4. 文件权限:777
  5. PHP memory_limit:128 MB
  6. max_size:8 MB
  7. 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);

未返回请求的数组,其中包含文件名和状态。为什么?我完全无能为力。

帮助请!

+0

图像上传到特定的文件夹或不是? –

+0

Hi @DeepParekh。图像上传到特定的文件夹中,是的。特定的文件夹是root:/ assets/images/trip/ – Zafar

+0

ok thj jst该图像的路径或名称未插入数据库中? –

回答

1

谢天谢地,经过广泛的调试后,这工作。该行

if($this->image_lib->resize()){ 
     $status = true; 
     $msg = $data['file_name']; 
    }else{ 
     $status = false; 
    } 

不起作用。后来,当我将其设置为display_error()方法时,表明我的服务器不支持GD库。这是操纵图形的基本库。所以,查询没有被执行,因为$ status变量被设置为false。

我用GD库模块重新编译了我的php。和bigno!它的工作现在。 谢谢你和我住在一起。 :)

相关问题