<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">You aren't deleting the record from the
database, just the file from the file system. You should add in
there a:<br>
<br>
db_query('DELETE FROM {files} WHERE fid = %d', $FID);<br>
<br>
Also do that on any other linked tables you have added in.<br>
<pre class="moz-signature" cols="72">Jamie Holly
<a class="moz-txt-link-freetext" href="http://www.intoxination.net">http://www.intoxination.net</a>
<a class="moz-txt-link-freetext" href="http://www.hollyit.net">http://www.hollyit.net</a></pre>
On 8/26/2012 10:25 AM, Kamal Palei wrote:<br>
</div>
<blockquote
cite="mid:CALO8XuXNqqV2kBgOyCA9XHYd6hgR5oacZxTBqD+UKLqnxKxYZQ@mail.gmail.com"
type="cite">
<div>Hi All</div>
<div>I am using Drupal 6.26.</div>
<div> </div>
<div>I am trying to upload a file. One user can upload only one
file.</div>
<div>After a while, if user wants to upload another file, I need
to delete the first file and upload the second file.</div>
<div>To delete the first file, I do a query to get the first file
name, deletes first file and uploads the second file.</div>
<div>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.</div>
<div>So I am not able to delete the second file.</div>
<div> </div>
<div>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.</div>
<div> </div>
<div>Please refer code below.</div>
<div> </div>
<div> global $user;<br>
$FID = -1;<br>
<br>
$result = db_query("SELECT fid, filepath FROM {resubmt_table}
LEFT JOIN {files} USING (fid) WHERE resubmt_table.uid = %d",
$user->uid);<br>
$obj = db_fetch_object($result);<br>
if($obj)<br>
{<br>
$FID = $obj->fid;<br>
if($obj->filepath)<br>
{<br>
if(file_exists($obj->filepath))<br>
{<br>
drupal_set_message("File exists deleting " .
$obj->filepath);<br>
unlink($obj->filepath);<br>
}<br>
else<br>
{<br>
drupal_set_message("File does not exists, so not able to
delete, file = " . $obj->filepath);<br>
}<br>
}<br>
}</div>
<div><br>
</div>
<div>Many times, I am not able to delete the file.</div>
<div>Please suggest how can I fix this issue.</div>
<div> </div>
<div>Thanks</div>
<div>Kamal</div>
<div>NECS, Bangalore</div>
<div> </div>
<div> </div>
<div> </div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
<br>
</body>
</html>