Welcome Guest, Not a member yet? Register   Sign In
Error uploading file pdf
#1

(This post was last modified: 03-19-2015, 06:31 PM by gloton.)

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);
}
}
Reply
#2

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
Passionate PHP Programmer & Codeigniter Developer :- Always happy to help you!
Reply
#3

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)
Reply
#4

This is my example

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

https://mega.co.nz/#!gVVnyCTY!hcGjm4YHIn...TXp8ehzzrg

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?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB