You aren't deleting the record from the
database, just the file from the file system. You should add in
there a:
db_query('DELETE FROM {files} WHERE fid = %d', $FID);
Also do that on any other linked tables you have added in.
Jamie Holly
http://www.intoxination.net
http://www.hollyit.net
On 8/26/2012 10:25 AM, Kamal Palei wrote:
Hi All
I am using Drupal 6.26.
I am trying to upload a file. One user can upload only one
file.
After a while, if user wants to upload another file, I need
to delete the first file and upload the second file.
To delete the first file, I do a query to get the first file
name, deletes first file and uploads the second file.
After a while, if user wants to upload another file, when I
do query to get the second file name (as I want to delete the
second file now), I always get the first file name.
So I am not able to delete the second file.
Probably database cache plays a role here, how can I make
sure, my query returns the latest data present in table, query
should not pick the data from cache.
Please refer code below.
global $user;
$FID = -1;
$result = db_query("SELECT fid, filepath FROM {resubmt_table}
LEFT JOIN {files} USING (fid) WHERE resubmt_table.uid = %d",
$user->uid);
$obj = db_fetch_object($result);
if($obj)
{
$FID = $obj->fid;
if($obj->filepath)
{
if(file_exists($obj->filepath))
{
drupal_set_message("File exists deleting " .
$obj->filepath);
unlink($obj->filepath);
}
else
{
drupal_set_message("File does not exists, so not able to
delete, file = " . $obj->filepath);
}
}
}
Many times, I am not able to delete the file.
Please suggest how can I fix this issue.
Thanks
Kamal
NECS, Bangalore