簡體   English   中英

使用CI上傳文件圖像

[英]Uploading file image Using CI

在我看來,我使用了form_open_multipart() ,我有:

<input type="file" name="user_photo" style="margin-top: 5px;" />

我的控制器中有這樣的配置:

$config['upload_path'] = './resources/uploads/';
$config['allowed_types'] = 'jpg|gif|png|bmp|jpeg';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);

if(!$this->upload->do_upload('user_photo')) {
echo $this->upload->display_errors('<p>', '</p>');
} else {
echo "<pre>"; print_r($this->upload->data());
}

但是,當我嘗試上傳文件類型為* .jpg的圖像文件時,出現如下錯誤: The file type you are attempting to upload is not allowed.
我的配置有什么問題嗎? 謝謝,。

如果您的Web服務器使用的是PHP v5.2.x,而您使用的是CodeIgniter 2.1.0,請降級至CodeIgniter 2.0.3,這樣就可以解決上傳問題。

在CodeIgniter 2.1.0中造成此問題的代碼有罪,是

$this->file_type = @mime_content_type($file['tmp_name']); 

/system/libraries/Upload.php 有關更多信息,請參見CodeIgniter 未解決問題列表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM