Welcome Guest, Not a member yet? Register   Sign In
File Upload difficulties
#1

[eluser]stevefink[/eluser]
Hi all,

I'm having marginal difficulty with the file upload helper. Here's my controller:

Code:
function carfax()
    {
        if($this->uri->segment(4) === FALSE)
        {
            redirect('', 'refresh');
        }
        
        if ($_FILES)
        {
            $data = array('upload_data' => $this->upload->data());
            log_message('debug', "message: " .print_r($data, TRUE));
        }
        
        $this->load->view('console/car_fax_view',array('error'=>''));
    }

Is there any reason why when I use $this->upload->data() I cannot see any of my files contents, however if I print_r $FILES, all of the information is there?

Thanks.

- sf
#2

[eluser]lefrog[/eluser]
Is your

$this->upload->do_upload();

in the same controller

I used the upload class recently and the data was there, here's my function

function upload_image($path, $name)
{
$rules['upload_path'] = $path;
$rules['allowed_types'] = 'jpg';
$rules['overwrite'] = true;
$this->load->library('upload', $rules);
// if the upload is not a gallery item
if ($name != "orig") {
$_FILES['userfile']['name'] = $name;
}
if ( ! $this->upload->do_upload() )
{
die($this->upload->display_errors());
}
// if the upload is a gallery item we need to return the filename so we can manipulate it
if ($name == "orig") {
$upload_data = $this->upload->data();
$temp_name = substr($upload_data['orig_name'], 0, -4);
//$new_path = substr($path, 2);
$old_name = $path . $upload_data['orig_name'];
$new_name = $path . $temp_name . ".jpg";
//die($old_name . " " . $new_name);
rename($old_name, $new_name);
return $upload_data['orig_name'];
}
}
#3

[eluser]coolfactor[/eluser]
You need to call the do_upload() function before the data() function will return the correct values.
#4

[eluser]Crafter[/eluser]
Use this check:
Code:
if ( isset($_FILES['userfile']['name'] ) && ($_FILES['userfile']['name'] != '') ) {
      }

And take Coolfactors advise to use the library correctly.




Theme © iAndrew 2016 - Forum software by © MyBB