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

[eluser]Unknown[/eluser]
Hello all,

I am facing a problem in file upload/delete related functions. Here's what is happening:

1. When I submit a file type field in a from my view, the file is uploaded successfully.

But when I edit the same record, and try to upload another file for the same record (such that previous file gets deleted and new selected file is uploaded) both delete and upload operations fail.

In my view I declare a form field name (receipt) and post this field's value to the controller.

Here is the code for this:-

<input name="receipt" type="file" id="receipt"/>

In the controller the post value is received and I assign it to the POST array too for additional processing:

$_POST['receipt'] = $_FILES['receipt']['name'];

Then the POST array is sent to the model.

In the Model, the insert operation works fine when I create the record for the first time. File uploads work fine.

But when I open the same record, and try to upload a new file, the previous file is not deleted, and the new file is also not uploaded.

Here's the code for it:

$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '3000';
$config['max_width'] = '1024';
$config['max_height'] = '768';

$this->load->library('upload',$config);
if ( !$this->upload->do_upload('receipt')){ // To upload the new file.

$this->template->set('system_message', 'Record Updated');
return false;
}
else{
$image_data = $this->upload->data();
}

$receipt_old_value = 'retrived from database';

unlink($receipt_old_value); // To delete the old file


Any help is appreciated.

Thanks,
Saahilwwaliaa


Messages In This Thread
File upload - by El Forum - 11-06-2012, 12:41 AM
File upload - by El Forum - 11-06-2012, 02:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB