i am using blueimp jQuery file upload for file uploader.This is my controller code.
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; } } }
i am getting the value of printing $file_details as bool(true).The uploaded file name(ie.name assigned by the upload library ) is not working.i want to get those details.how to get it?if anybody knows pls help.
Advertisement
Answer
$this->upload->do_upload('files');
returns true
if the file was uploaded correctly. What you want probably is $this->upload->data()
. Also, I’ll suggest changing the name of the file(not necessary but helps in debugging). Below is the working code on this matter –
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']; }
See if it helps you.