In my form have 3 file upload input option.
bot are going to different directory. I can work with one directory but not work with multiple.
My code
$config['upload_path'] = './uploads/video';
$config['allowed_types'] = 'flv|mov|m4v|mp4';
$config['max_size'] = '30720';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
$video_upload=$this->upload->data();
$config2['upload_path'] = './uploads/video';
$config2['allowed_types'] = 'jpg|jpeg|bmp|png';
$config2['max_size'] = '30720';
$config2['encrypt_name'] = TRUE;
$this->load->library('upload', $config2);
$this->upload->do_upload('thumbnail1');
$thumbnail_upload=$this->upload->data();
here video file upload successfully but image file not upload
$this->load->library() doesn't reload or reinitialize the library if it's already loaded.
In this case, you need to modify the existing loaded library options:
$this->upload->initialize($config2);
instead of
$this->load->library('upload', $config2);
Should do the trick.
Related
You have added $ config ['encrypt_name'] = TRUE; For the upload code because some user images are called spaces and problems causing problems lifting
After uploading the file its name is changed but I try to take the file name to send it to the database
this way
$ img1 = $ _FILES ['img1'] ['name'];
But I get the original file name before changing
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['overwrite'] = FALSE;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
If you loop trough each photo and initialize the library with the $_FILES['file_name'] this will help you
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['overwrite'] = FALSE;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload('file_name');
$image_uploaded = $this->upload->data();
$filename = pathinfo($image_uploaded['full_path']);
$insert['photo'] = $filename['basename'];
$this->db->insert('your_table', $insert);
Don't fall back to the $_FILE superglobal. Since you're using CI, stick to CI's upload wrapper
Assign the output of the upload process to a variable like this:
$your_variable = $this->upload->data();
By doing this, you get all the upload data in your newly created $your_variable array:
$your_variable['file_name'] // encrypted name
$your_variable['file_type'] // MIME type such as image/jpeg or application/pdf
$your_variable['file_path'] // self explanatory
$your_variable['raw_name'] // encrypted name without the extension
$your_variable['orig_name'] // original name
$your_variable['client_name'] // name the file had on the client's computer
$your_variable['file_ext'] // self explanatory
$your_variable['file_size'] // self explanatory. Size in Kb
$your_variable['is_image'] // 1 if yes, 0 otherwise
$your_variable['image_width'] // only for images
$your_variable['image_height'] // only for images
$your_variable['image_type'] // only for images
$your_variable['image_size_str'] // only for images
I'm pretty sure those are all you get as of CI 3.1.10 (but I may have forgotten a couple, if so I apologize)
You need the ['file_name'] element for your purposes.
Going back to the $_FILE superglobal will not work, as CI won't modify its values
I successfully create multiple file upload. But, for some reason it fails to upload zip type files.
$config['upload_path'] = FCPATH."assets/uploads/";
$path = $config['upload_path'];
$config['allowed_types'] = 'gif|jpg|jpeg|png|bmp|doc|docx|ppt|pptx|xls|xlsx|txt|pdf|sql|html|rar|zip|7z';
$config['max_size'] = '5120';
$this->load->library('upload', $config);
$this->upload->initialize($config);
If I add this $this->upload->set_allowed_types('*');. The zip files are uploaded. But, I don't want to use this. Because it allows all type to be uploaded.
I am uploading a file on server and storing the its path in database in codeigniter, however i am after the upload i am not getting the correct path
The code that i have used is
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'doc|docx|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
$data = array('upload_data' => $this->upload->data());
$image_path = $data['upload_data']['full_path'];
I wish to save the path that i am getting in $image_path inside database.
Now the path that i get is something like this
/home/litehepn/public_html/project_name/uploads/xyz.docx
But the path that i want is
project_name/uploads/xyz.docx
Can anyone please tell how to get the correct path
This is the correct path. Because you have stored your files inside that home directory. But You can use chop($url,"/home/litehepn/public_html/"); for getting it.
I can't upload ogg / ogv file. the error message is
The filetype you are attempting to upload is not allowed.
I have tried this in the mimes.php
'ogg' => array('application/x-ogg', 'application/ogg', 'audio/x-ogg, application/octet-stream'),
'ogv' => array('application/ogv', 'video/ogv')
and in the controller
$config['upload_path'] = 'assets/assets/video/';
$config['allowed_types'] = 'ogv|ogg';
$config['file_name'] = "samsame";
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload('videoname');
$error = $this->upload->display_errors();
You have to initialize the $config array, so your problem will be solved. You are trying to upload without initializing. Please write the below line after loading the library.
$this->upload->initialize($config);
Also check that your form must be multipart
You can also rewrite the $config array if above solution dose't work. Here sample_simage
is the name of input type.
$allowed_types = 'ogg|ogv';
$config['upload_path'] = './assets/uploads/';
$config['allowed_types'] = substr($allowed_types, strpos($allowed_types,substr($_FILES['sample_simage']['name'], -3)), 3);
$this->load->library('upload', $config);
$this->upload->do_upload('sample_simage');
Here is my controller code but only jpg and png file are uploaded I also changed it my process model.php also.
Is there any way to change it? And it doesn’t show any warning. You can check it from here but you need to register first...
public function saveTestimonial() {
$config['upload_path'] = './testimonial_photo/';
$config['allowed_types'] = 'gif|jpg|png|psd|zip|tif|ai|eps';
$config['max_size'] = '1024';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
You should declare file upload like the below code. Since you are uploading images, docx, zip files you should not declare max_width and max_height. But you can change the max_size for the file.
$config['upload_path'] = 'testimonial_photo/';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->set_allowed_types('gif|jpg|png|jpeg|zip|pdf|doc|docx');
$this->upload->do_upload('filename_in_html_input')