[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>
<?= form_label('My File:', 'my-file').form_upload(array( 'name' => 'my-file', 'id' => 'my-file')); ?>
</p>
<?=
form_submit('submit', 'Send');
?>
<?=
form_close();
?>
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