2017-01-23 154 views
2

我不能將圖像上傳到文件夾在線,但它在本地主機上完美工作。Codeigniter文件上傳不能在Live服務器上工作

下面是我的代碼

$this->load->helper(array('form', 'url')); 
if (empty($_FILES['photo']['name'])) { 
    $image=$this->input->post('image'); 
} else { 
    $config = array(
     'upload_path' => "uploads/", 
     'allowed_types' => "gif|jpg|png|jpeg", 
    ); 
    $this->load->library('upload',$config); 

    if($this->upload->do_upload('photo')) { 
     $upload_data = $this->upload->data(); 
     $image = $upload_data['file_name']; 
    } else { 
     $error = array('error' => $this->upload->display_errors()); 
     redirect(base_url().'uploaderror'); 
    } 
} 

請幫助尋找解決方案 感謝

傢伙感謝您的幫助,問題是與服務器 PHP版本我固定它

+0

什麼是錯誤? –

+0

其未顯示任何錯誤 –

+0

檢查您的服務器文件夾權限。它應該是777. image name正在更新到數據庫中? –

回答

1

也可能是試試這個代碼由於PHP服務器版本和它的選項。

1).logging到您的cPanel賬戶

2)。在軟件部分,點擊 「選擇PHP版本」。

3).tap「fileinfo」chexbox在php選項中,像下面的照片。

![tap the "fileinfo chexbox"][and save]

1
$base_path = $this->config->item('upload_path'); 

     $config['upload_path'] = $base_path.'/folder_name/'; 
     $config['allowed_types'] = config('allowed_extensions'); 
     $config['max_size'] = config('max_upload_file_size'); 
     $config['encrypt_name'] = true; 
     $file_name = ''; 

     $this->load->library('upload', $config); 

檢查此代碼。

+0

仍然相同問題 –

+0

是否將您的其他數據更新到db正確? –

1

在控制器

<?php 
     public function _upload_files() 
     { 
       $this->session->unset_userdata('upload_data'); 
       $config['upload_path']   = FCPATH.'uploads'.DIRECTORY_SEPARATOR; 
       $this->_check_file_upload_path($config['upload_path']);// check if upload path exists, if not creates one 
       $config['allowed_types']  = "gif|jpg|png|jpeg"; 
       $config['encrypt_name']   = TRUE;// file name will be encrypted 
       $this->load->library('upload', $config); 
       if (!$this->upload->do_upload('photo')) 
       { 
         echo $this->upload->display_errors('',''); 
         return FALSE; 
       }  
       var_dump($this->upload->data()); 

     } 

     private function _check_file_upload_path($upload_path) 
     { 
       if(! is_dir($upload_path)) 
         mkdir($upload_path,0777,TRUE); 
       return $upload_path; 
     } 
相關問題