I'm using PHP 5 and Codeigniter 3 on Ubuntu Linux.
I need to upload and store user files on the server, but before upload I need to create directory for user where files will be stored. Directory name is based on userdata hashed with md5.
Also Im checking if directory is already created/exists on server, otherwise should be created.
public function uploadImage(){
$id = $this->session->userdata('id');
$dir_name = md5($id); // create hashed dir name
$user_dir = base_url() . 'uploads/user' . '/' . $dir_name;
// print_r($user_dir);
if(!file_exists($user_dir)){
mkdir($user_dir, 0777);
print_r("created");
}else{
print_r("directory exists");
}
}
When I run code, it says created, but I cant see directory. It does not exist in uploads/users folder. Please help me, where Im wrong. Many thanks
USE FCPATH
public function uploadImage(){
$id = $this->session->userdata('id');
$dir_name = md5($id); // create hashed dir name
/*
You may need / after FCPATH
$user_dir = FCPATH . '/uploads/user/' . $dir_name;
*/
$user_dir = FCPATH . 'uploads/user/' . $dir_name;
// print_r($user_dir);
if(!file_exists($user_dir)){
mkdir($user_dir, 0777);
// @mkdir($user_dir, 0777, true);
print_r("created");
} else {
print_r("directory exists");
}
}
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.