This type of question has been asked here before, but no solution is working in this case. I have a website admin panel developed in CI
and my directory looks like this.
uploads
/stores
/products
admin
/application
/system
/assets
Now, I have to upload files in the subfolders of uploads that are residing in the root via a controller.
I have looked around other solutions and I have tried followings:
$upload_path = './uploads/stores/';
Above code is working when I keep uploads folder inside the admin folder. But I need to keep the uploads folder outside the admin.
I looked at the path CI
uses and based on this, here is another method I tried
$upload_path = '../../uploads/stores/';
and also,
$upload_path = '/home/domain/public_html/uploads/stores/';
But this gives me following error.
The path to the image is not correct.
I'm completely lost here. Any suggestion is appreciated.
You can assign following path when you upload your images.
$uploadpath = $_SERVER['DOCUMENT_ROOT'].'/your_folderame';
The document root directly under which the current script is executing, as define in the server configuration file.
Use APPPATH and FCPATH to make the correct structure:
APPPATH : path to application folder
echo FCPATH .'uploads'.DIRECTORY_SEPARATOR.'stores';
if($this->input->post('img_status') == 3){//here 3 is indicating that new image is selected
if(!empty($_FILES['image']['name'])){
$name_array = '';
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
$config['max_size'] = '1000';
$config['max_width'] = '1280';
$config['max_height'] = '1280';
$this->load->library('upload');
$this->upload->initialize($config);
if(!$this->upload->do_upload('image'))
$this->upload->display_errors();
else {
$fInfo = $this->upload->data(); //uploading
$this->gallery_path = realpath(APPPATH . '../uploads');//fetching path
$config1 = array(
'source_image' => $fInfo['full_path'], //get original image
'new_image' => $this->gallery_path.'/thumb', //save as new image //need to create thumbs first
'maintain_ratio' => true,
'width' => 250,
'height' => 250
);
$this->load->library('image_lib', $config1); //load library
$this->image_lib->resize(); //generating thumb
$imagename=$fInfo['file_name'];// we will get image name here
$dataInsert['image'] = $imagename;
}
}
}
else if($this->input->post('img_status') == 2){
$dataInsert['image'] = NULL;
}
Directory handling is very easy for each directoy you want to move up ../ so
Try this, just keep adding ../ until you get where you want to go. Code: $dir = "../../gallery/safe/";
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.