[eluser]Pedro Correia[/eluser]
I'm using the file uploading and came across a small but extremely frustrating problem with i'll explain with some "pseudo" code:
Code:
public function somemethod(){
...
// uploading an image file
if ($this->upload->do_upload('image_file'))
{
// get the upload data and store it in an array
$data['upload'] = $this->upload->data();
// take the upload data array and save it to a db
if(!$this->mymodel->save_upload_data($data)){
// db write fails, delete that stray image from our file system
if(file_exists($uploaded_image_path))
unlink($uploaded_image_path);
}
}
...
}
The problem i'm having is that when the database write part fails and i try to delete the stray image file, it is not in its final upload destination path.
It only is visible and available for manipulation about a second later.
I've read some similar complaints on the php.net documentation comments where a couple of users state that the move_uploaded_file sometimes has a sort of asynchronous behavior.
However using php's copy function behaves the same.
I've tried to delete the file in the File Uploading class code right after the file has been moved from its temp_dir to its final destination and it works just fine.
Doing it from a controller fails.
I was developing on a windows machine and thought it might me the cause, with some file system quirks, but running my code on linux (debian) gets the same results.
I'm using a workaround and storing the "stray" image paths somewhere else and deleting them later but it's really frustrating that the File Uploading class do_upload() method returns true and it's only "trueish".
Anyone have any insight on this one?
Thanks in advance,
Pedro