File Upload difficulties - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: File Upload difficulties (/showthread.php?tid=2984) |
File Upload difficulties - El Forum - 09-03-2007 [eluser]stevefink[/eluser] Hi all, I'm having marginal difficulty with the file upload helper. Here's my controller: Code: function carfax() 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 File Upload difficulties - El Forum - 09-03-2007 [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']; } } File Upload difficulties - El Forum - 09-03-2007 [eluser]coolfactor[/eluser] You need to call the do_upload() function before the data() function will return the correct values. File Upload difficulties - El Forum - 09-04-2007 [eluser]Crafter[/eluser] Use this check: Code: if ( isset($_FILES['userfile']['name'] ) && ($_FILES['userfile']['name'] != '') ) { And take Coolfactors advise to use the library correctly. |