上传文件的临时名称没有进入blueimp jQuery文件上传



我使用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(的值。上传的文件名(即上传库分配的名称(不起作用。我想获取这些详细信息。如何获取?如果有人知道,请帮忙。

如果文件上传正确,则$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'];
}

看看它是否对你有帮助。

最新更新