Here is my Base controller for upload function
protected function upload_data($folder, $name) {
$config = array(
'upload_path' => "./upload/".$folder,
'overwrite' => FALSE,
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
);
if ($name == "image") {
$config['allowed_types'] = "gif|jpg|png|jpeg";
// $config['max_height'] = "450";
// $config['max_width'] = "400";
} else if ($name == "video") {
$config['allowed_types'] = "mp4|webm|mpeg";
$config['max_size'] = "5120000";
} else if ($name == "cv_file") {
$config['allowed_types'] = "pdf|doc|docx";
}
$this->load->library('upload', $config);
if($this->upload->do_upload($name)) {
$data = array('upload_data' => $this->upload->data());
unset($this->upload);
return $data;
} else {
$error = array('error' => $this->upload->display_errors());
unset($this->upload);
return $error;
}
}
Below is my controller code to access this upload function
public function uploadCheckLists()
{
$post_data = $this->input->post();
$cv_data = $this->upload_data('files', 'cv_file');
if (isset($cv_data['upload_data'])) {
$file_path = $cv_data['upload_data']['file_path'];
$data['cv_name'] = $cv_data['upload_data']['file_name'];
}
}
This is working fine. But When I want to create user related folder dynamically that folder was creating in root folder and not in the specified path. Here is my code to create folder dynamically
When I replace this line
$cv_data = $this->upload_data('files', 'cv_file');
with below one it is not working and folder is creating in root folder.
$cv_data = $this->upload_data('files/'.mkdir($post_data['selected_user_enc_id']), 'cv_file');
So the folder should create like files/58 (user id)
can any one help me in this regard where I am doing wrong? Any help would be greatly appreciated.
Must check if not then create folder on you path
if (!file_exists('./upload/'.$folder)) {
mkdir('./upload/'.$folder, 0777, true);
}
You will create folder. It's work on me.
Thank You
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.