[英]Codeigniter 2 File Upload Not Working / Possible Folder Permission Issue
I'm trying to upload a file on CodeIgniter 2 but it fails. 我正在尝试在CodeIgniter 2上上传文件,但失败。 I tried a few different ways, actually CI is getting the file and trying to put it in destination folder but I think there is a problem with folder permissions.
我尝试了几种不同的方法,实际上CI正在获取文件并将其放入目标文件夹,但我认为文件夹权限存在问题。 Because I can echo file name etc.
因为我可以回显文件名等
This is my model file's related part: 这是我的模型文件的相关部分:
$config = array
(
'upload_path' => 'uploads/campaigns/data',
'allowed_types' => 'csv',
);
$this->upload->initialize($config);
$this->upload->do_upload('file');
$file = $this->upload->data();
$file_name = $file['file_name'];
if(!empty($file_name)) {
echo $file_name;
}
else {
echo $this->upload->display_errors();
}
With this code, I can see filename but file is not uploading. 使用此代码,我可以看到文件名,但文件未上传。 I only have root account on this server and all files created and owned by root.
我在该服务器上只有root帐户,所有文件都由root创建和拥有。 Folders have 777 permission.
文件夹具有777权限。 What should I try now?
我现在应该尝试什么?
Thank you! 谢谢!
Use this to track your errors 使用它来跟踪您的错误
if ( ! $this->upload->do_upload())
{
echo $this->upload->display_errors();
}
else
{
echo "success";
}
I hope you loaded the library as well 我希望您也加载了图书馆
EDIT 01 编辑01
$config['upload_path'] = './uploads/campaigns/data';
$config['allowed_types'] = 'csv';
$config['max_size'] = '5120'; # 5MB allowd
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
echo $this->upload->display_errors();
}
else
{
echo $this->upload->data();
}
And in application/config/mimes.php
并在
application/config/mimes.php
Check there is a csv
format. 检查是否有
csv
格式。 If ot exist add this on array as new item 如果存在,则将其作为新项添加到数组中
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.