CodeIgniter Forums
Error uploading file pdf - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forum-11.html)
+--- Thread: Error uploading file pdf (/thread-1543.html)



Error uploading file pdf - gloton - 03-19-2015

Sorry, I do not speak English, but I have a question.
I need to upload one file only with extension pdf.

My problem is only using browser firefox, i not have problem using chrome.

My code is

Code:
public function uploadFile()
{
$config['upload_path'] = dirname($_SERVER["SCRIPT_FILENAME"])."/upload/";
$config['upload_url'] = base_url()."upload/";
$config['allowed_types'] = "pdf";
$config['overwrite'] = TRUE;
$config['max_size'] = "1000KB";
$config['file_name'] = "namearchivo";
$this->load->library('upload', $config);

if($this->upload->do_upload())
{
$file_name = $_FILES['userfile']['name'];
redirect($urlAnterior);
} else {
echo "No ok";
redirect($urlAnterior);
}
}



RE: Error uploading file pdf - techbat - 03-19-2015

You made some misconfiguration in upload method code,
  1. `upload_url` not any config type in upload library.
  2. `max_size` value by default in KB not need to add in value
  3. better to use more Upload library functions.
  4. you should create ./upload directory on project root folder and use `FCPATH` constant to go folder location.

see below correct sample code

PHP Code:
function uploadFile() {
 
   $config['upload_path'] = FCPATH "/upload/";
 
   $config['allowed_types'] = "pdf";
 
   $config['overwrite'] = TRUE;
 
   $config['max_size'] = "1000";
 
   $config['file_name'] = "namearchivo";
 
   $this->load->library('upload'$config);

 
   if ($this->upload->do_upload()) {
 
       $file_data $this->upload->data();
 
       $file_name $file_data['file_name'];
 
       redirect($urlAnterior);
 
   } else {
 
       echo $this->upload->display_errors('<p>''</p>');
 
       //redirect($urlAnterior);
 
   }


Probably solution would be work for you  Smile


RE: Error uploading file pdf - Avenirer - 03-20-2015

If it works with one browser and not with the other, then the problem must be the browser (or the form where you upload the files)


RE: Error uploading file pdf - gloton - 03-22-2015

This is my example

url test http://localhost/CodeIgniter-2.2.1/uploads/do_upload

https://mega.co.nz/#!gVVnyCTY!hcGjm4YHInrEypwx5CeUZH87UaNaRR1NjTXp8ehzzrg

In google chrome all ok.. I don't understand why not it works in firefox (last version), How is it possible?.  Confused

Any idea? or some alternative?