2016-07-20 71 views
3

這種類型的問題在此處已經提到,但在這種情況下沒有解決方案。我在CI開發了一個網站管理面板,我的目錄看起來像這樣。Codeigniter將文件上傳到安裝文件夾以外的根目錄

uploads 
    /stores 
    /products 
admin 
    /application 
    /system 
    /assets 

現在,我必須上傳通過控制器駐留在根目錄上的子文件夾中的文件。

我環顧四周其他的解決方案,我已經試過如下:當我把上傳文件夾中的管理文件夾內

$upload_path = './uploads/stores/'; 

上面的代碼是工作。但我需要保持管理員以外的上傳文件夾。

我看着路CI用途及在此基礎上,這裏是另一種方法,我試過

$upload_path = '../../uploads/stores/'; 

而且,

$upload_path = '/home/domain/public_html/uploads/stores/'; 

但是這給了我下面的錯誤。

圖像的路徑不正確。

我完全迷失在這裏。任何建議表示讚賞。

+0

你試過了嗎$ config ['upload_path'] ='./uploads/stores/'? 如果它不工作,那麼使用file_exist函數檢查它是否在同一位置。 – Bhavin

+0

我已經試過這個,但沒有工作 –

+0

print_r($ _ FILES);正在返回所有文件的數據?你可以用代碼更新你的問題,因爲do_upload()可能有問題。 – Bhavin

回答

4

您可以指定以下路徑你上傳你的圖片。

$uploadpath = $_SERVER[DOCUMENT_ROOT'].'/folderame'; 

直接在其下執行當前腳本的文檔根,如服務器配置文件中的定義。

+0

版本的輸出:'$ uploadpath = $ _SERVER ['DOCUMENT_ROOT']。'/ folderame';' –

+0

欲瞭解更多詳情,請訪問此處這肯定是用戶直接採取的答案[鏈接](http://howcanfix.com/32558/codeigniter-upload-files-at-root-directory-outside-of-the-installation-folder) –

+0

@ankitsuthar此鏈接已經從這個頁面採取了問題和答案。 –

1

使用APPPATH和FCPATH做出正確的結構:

  1. FCPATH:路徑文件夾中包含你的項目
  2. APPPATH:路徑應用程序文件夾

    echo FCPATH .'uploads'.DIRECTORY_SEPARATOR.'stores'; 
    
+0

這段代碼返回了我之前嘗試過的相同路徑,這給我錯誤。 –

+0

您可以在代碼中顯示路徑 – pradeep

+0

/home/domain/public_html/uploads/stores –

0
if($this->input->post('img_status') == 3){//here 3 is indicating that new image is selected 
    if(!empty($_FILES['image']['name'])){ 
     $name_array = ''; 
     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|jpeg|png|bmp'; 
     $config['max_size'] = '1000'; 
     $config['max_width'] = '1280'; 
     $config['max_height'] = '1280'; 
     $this->load->library('upload'); 
     $this->upload->initialize($config); 
     if(!$this->upload->do_upload('image')) 
      $this->upload->display_errors(); 
     else { 
      $fInfo = $this->upload->data(); //uploading 
      $this->gallery_path = realpath(APPPATH . '../uploads');//fetching path 
      $config1 = array(
        'source_image' => $fInfo['full_path'], //get original image 
        'new_image' => $this->gallery_path.'/thumb', //save as new image //need to create thumbs first 
        'maintain_ratio' => true, 
        'width' => 250, 
        'height' => 250 

       ); 
      $this->load->library('image_lib', $config1); //load library 
      $this->image_lib->resize(); //generating thumb 
      $imagename=$fInfo['file_name'];// we will get image name here 
      $dataInsert['image'] = $imagename; 
     } 
    } 
} 
else if($this->input->post('img_status') == 2){ 
    $dataInsert['image'] = NULL; 
} 
+1

只有代碼,我不知道如何以及如果這篇文章回答這個問題。請參閱[如何編寫一個好的答案](https://stackoverflow.com/help/how-to-answer)並進行相應的編輯。 – Nuageux

相關問題