Page 1 of 1

Delete a file...

Posted: Sat Jul 26, 2008 4:06 am
by panprasath
In my program i have some files in "temp" folder...that contain the fillowing files

hari8975495.jpg
hari8975408.jpg
guru9843.jpg
main8457.jpg
hari89749957.gif
i want to delete all the file starting with hari...how i do this.....But i put unlink(temp\hari*.*);
but it so error....

Re: Delete a file...

Posted: Sat Jul 26, 2008 4:12 am
by WebbieDave
Use readdir to loop through the directory contents, checking if filename starts with hari using strpos.

Re: Delete a file...

Posted: Sat Jul 26, 2008 7:03 am
by php000developer
first make a form and add selecting box for selecting the files to delete from database
add this code to make a deleting form
<form action="delete1.php" method="post">
<select name="area" >
<? $res=mysql_query("SELECT * FROM area order by area");
if (mysql_num_rows($res)== 0)
echo "There is no data";
else
for($i=0;$row=mysql_fetch_assoc($res);$i++)
{
print "<option>$row[area]</option>";
}

?></select><INPUT TYPE=SUBMIT NAME="submitform" VALUE="Remove"></form>


then add this code to "delete1.php" file, you can change the name of that file but remember change in both files

<?
$area=$_POST['area'];
$name=$_POST['name'];

$query="DELETE from tablename WHERE name='".$fieldname."'";
$query1="DELETE from area WHERE area='".$area."'";
mysql_query($query) or die ('Cannot delete file');
mysql_query($query1) or die ('Cannot delete file');
echo "Record Deleted!";
?>

Re: Delete a file...

Posted: Tue Aug 05, 2008 5:14 am
by panprasath
Thank you for your help...