2016-12-27 57 views
1

我想在我的網站上使用codeigniter的上傳庫添加文件上傳功能。codeigniter do_upload不工作

這裏是我的視圖文件(Display.php的):

<html> 
<body> 
    <form method="post" action="" enctype="multipart/form-data"> 
     <input type="file" name="filename" /> 
     <input type="submit" name="submit" id="submit" value="submit"/> 
    </form> 
</body> 
</html> 

和這裏的控制器:

public function testupload() 
{ 
    if (! empty($_FILES)) 
    { 
    echo 'start upload'; 
    $config['upload_path'] = './assets/img/tempfile/'; 
    $this->load->library('upload'); 
    $this->upload->initialize($config); 
    if (! $this->upload->do_upload('filename')) 
    { 
     echo 'error!'; 
    } 
    else 
    { 
     echo 'success!'; 
    } 
    echo 'end upload'; 
    } 
    $this->load->view('display', $this->data); 
} 

但代碼看起來$this->upload->initialize($config);之後停止該文件沒有上傳,並有根本沒有消息。只有'start upload'消息出現;不出現echo 'success'echo 'error'echo 'end upload'

這是爲什麼?誰能幫我??

+1

使用'$ this-> upload-> display_errors()'調試錯誤 –

+1

啓用調試模式。 'ini_set('display_errors','1'); error_reporting(E_ALL);'並打印這個以及'$ this-> upload-> display_errors()'; – Naga

+0

nope。沒有任何工作。如果放在'$ this-> upload-> do_upload('文件名')之後,甚至沒有簡單的'echo'blabla';';我嘗試了@Naga的建議,但仍然沒有任何結果。 – dapidmini

回答

0

嘗試這樣的....從

$config['upload_path'] = './assets/img/tempfile/'; 

$config['upload_path'] = 'assets/img/tempfile/'; 
+0

相同的結果..提交後,它只顯示'開始上傳「,並沒有在那之後.. – dapidmini

+0

我想你必須設置更多'$ config []'..在這裏https://www.codeigniter.com/userguide3/libraries/file_uploading.html –

+0

試圖從你的鏈接添加4其他$配置,但仍然相同.. – dapidmini

0

變化 只需添加這行

$config['upload_path'] = './assets/img/tempfile/'; 

後0

,或者您也可以設置有鑑於此頁

action="<?php echo base_url('YourController/testupload');?>" 
+0

'。/ assets/img/tempfile /'和''assets/img/tempfile /''之間有什麼不同? –

0

我檢查這個代碼這項工作完美

public function testupload() 
{ 
    if (! empty($_FILES)) 
    { 
    echo 'start upload'; 
    $config['upload_path'] = './assets/img/tempfile/'; 
    $this->load->library('upload',$config); 
    if (! $this->upload->do_upload('filename')) 
    { 
     $error = array('error' => $this->upload->display_errors()); 
     $this->load->view('display', $error); //loads the view display.php with error 
    } 
    else 
    { 
     echo 'success!'; 
    } 
    echo 'end upload'; 
    $data = array('upload_data' => $this->upload->data()); 
    $this->load->view('display', $data); //loads view display.php with data 
    } 

} 
0

這是由於PHP服務器版本和它的選項。

1)。去的cPanel帳戶

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

3).tap「fileinfo」chexbox在php選項並保存。

現在您可以完美地上傳文件。