上传的文件的临时名称没有进入 blueimp jQuery 文件上传
Posted
技术标签:
【中文标题】上传的文件的临时名称没有进入 blueimp jQuery 文件上传【英文标题】:temporary name of file uploaded not getting in blueimp jQuery file upload 【发布时间】:2020-10-28 11:01:42 【问题描述】:我正在为文件上传器使用 blueimp jQuery 文件上传。这是我的控制器代码。
public function savedocument()
$response = array('status' => 'failed', 'message' => 'Unknown reason');
$config = array();
$config['upload_path'] = 'upload path';
$config['allowed_types'] = 'gif|jpg|png|pdf|doc|docx';
$config['max_size'] = '20480';
$config['overwrite'] = FALSE;
//var_dump($config);
$this->load->library('upload', $config);
$files = $_FILES;
for($i=0; $i< count($_FILES['files']['name']); $i++)
$_FILES['files']['name']= $files['files']['name'][$i];
$_FILES['files']['type']= $files['files']['type'][$i];
$_FILES['files']['tmp_name']= $files['files']['tmp_name'][$i];
$_FILES['files']['error']= $files['files']['error'][$i];
$_FILES['files']['size']= $files['files']['size'][$i];
$this->upload->initialize($config);
if (!$this->upload->do_upload('files'))
$response['message'] = $this->upload->display_errors();
else
$file_details = $this->upload->do_upload('files');
$response['status'] = 'success';
$response['message'] = $file_details;
我得到了将 $file_details 打印为 bool(true) 的值。上传的文件名(即上传库分配的名称)不起作用。我想获取这些详细信息。如何获取它?如果有人知道的请帮忙。
【问题讨论】:
【参考方案1】:$this->upload->do_upload('files');
返回 true
如果文件上传正确。你想要的可能是$this->upload->data()
。另外,我建议更改文件的名称(不是必需的,但有助于调试)。以下是有关此问题的工作代码-
for($i = 0; $i < count($_FILES['files']['name']); $i++)
$_FILES['user_file']['name'] = $_FILES['files']['name'][$i];
$_FILES['user_file']['type'] = $_FILES['files']['type'][$i];
$_FILES['user_file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
$_FILES['user_file']['error'] = $_FILES['files']['error'][$i];
$_FILES['user_file']['size'] = $_FILES['files']['size'][$i];
$fileName = 'user_file';
$config['upload_path'] = 'your-path-here';
$config['allowed_types'] = 'gif|jpg|jpeg|png|GIF|JPG|PNG|JPEG';
$config['max_size'] = 6096;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->initialize($config);
$uploaded = $this->upload->do_upload($fileName);
if ( ! $uploaded )
$error = array('error' => $this->upload->display_errors());
else
$upload_data = $this->upload->data(); // You'll get all the data of the uploaded file here.
$file = $upload_data['file_name'];
看看对你有没有帮助。
【讨论】:
以上是关于上传的文件的临时名称没有进入 blueimp jQuery 文件上传的主要内容,如果未能解决你的问题,请参考以下文章
BlueImp 文件上传“错误:方法不允许” - Laravel 4 路由问题