File Upload Problem

#1
[eluser]prezet[/eluser]
Hi,

I've got a small problem where I can't seem to use the Upload class properly.

I've generated a multipart form with the form helper as required for file uploads as follows:

Code:
<?=
form_open_multipart($_SERVER['PHP_SELF'], array( 'id' => 'my-form' ));
?>

<p>
  &lt;?= form_label('My File:', 'my-file').form_upload(array( 'name' => 'my-file', 'id' => 'my-file')); ?&gt;
</p>

&lt;?=
form_submit('submit', 'Send');
?&gt;

&lt;?=
form_close();
?&gt;


Here is my controller code to handle the file upload:

Code:
// Load upload class
$this->load->library('upload');
                
// Set config rules
$config['upload_path'] = '/myuploads/';
$config['allowed_types'] = 'jpg|gif';
$config['max_size']    = '1024';
$config['remove_spaces'] = true;
                
// Initialize rules                
$this->upload->initialize($config);
                
// Perform upload
if(!$this->upload->do_upload()){
print '...oops, something went wrong';

} else {
  print 'oh yeah! it worked';
}

// Lets see what's going on...
print_r($_FILES);
print_r($this->upload->data());

Basically, nothing is being returned from the data method. The standard PHP $_FILES array shows the file and it's temporary path etc as it should, but the data() method returns a blank array like this:

Code:
Array ( [file_name] => [file_type] => [file_path] => /myuploads/ [full_path] => /myuploads/ [raw_name] => [orig_name] => [file_ext] => [file_size] => [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => )

With an error message of 'You did not select a file to upload.'

So am I doing something wrong?

Thanks

#2
[eluser]Colin Williams[/eluser]
Either rename you upload field to 'userfile' or change the call to do_upload() so it passes the correct field.

Code:
// Perform upload
if(!$this->upload->do_upload('my-file')){

#3
[eluser]prezet[/eluser]
Thank you. In my haste to read the documentation I obviously missed that tiny detail.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.