Codeigniter上传文件无法在线运行,但可以在本地主机上运行 [英] Codeigniter upload file not working online but works on localhost
问题描述
我想问一下codeigniter上传。
I want to ask about codeigniter upload.
Codeigniter版本2.1.4
Codeigniter version 2.1.4
我无法在线将图像上传到文件夹中,但是在 localhost
上可以正常使用。
I cant upload the image into the folder online, but it works perfectly on localhost
.
我上传图片的代码
$config['upload_path'] = './assets/frontend/images/banner/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->upload->initialize($config);
$this->upload->do_upload('BannerImg');
$banimg = $this->upload->data();
$bantitle = $this->input->post('BannerTitle');
$bandesc = $this->input->post('BannerDesc');
$this->banner_model->addBanner($banimg,$bantitle,$bandesc);
您知道出了什么问题吗?
Do you know what's the problem?
已经尝试搜索它,但找不到解决方案。
Already try searching for it but can't find the solution.
请帮助别人。
谢谢。
推荐答案
由于我们在注释中发现了问题,因此我将其发布在此处作为参考。基本上,问题在于codeigniter中的 upload_class
似乎与某些mime类型有关。看到类似的问题:
Since we found the problem in the comments, i'll just post it here as a reference. Basically the issue is with the upload_class
in codeigniter which seems to be bugged involving some mime types. See similar problems:
CodeIgniter ;不允许使用您尝试上传的文件类型。 (与1不同)。
引用上面第1点接受的答案:
您使用的是Firefox,不是吗?
Quoting the accepted answer from point 1 above:
You are using Firefox, aren't you?
您可以尝试查看 system / libraries / Upload.php
第199行:
You could try looking at system/libraries/Upload.php
line 199:
$this->_file_mime_type($_FILES[$field]);
将该行更改为:
$this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();
然后上传您的 .wmv
文件。它会显示类似 application / octet-stream
之类的内容。将其添加到您的 mimes.php
中。希望获得帮助=)
Then do upload your .wmv
file. It would show something like application/octet-stream
or whatever. Add that to your mimes.php
. Hope this help =)
类似的答案此处
注意:
在您的情况下,可能不会完全相同,但问题相似,您应该找到相关文件输入答案中的类型,然后将其添加到 mimes.php
文件中以解决此问题。
Note:
In your case it won't probably wont be exactly the same but the issue is similar and you should find the relevant file types as in the answer and add them to the mimes.php
file to solve this issue.
某些链接:
- CodeIgniter forum's thread
- Mimetype corruption in Firefox
- Getting around IE’s MIME type mangling
这篇关于Codeigniter上传文件无法在线运行,但可以在本地主机上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!