Delete a file...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
panprasath
Forum Newbie
Posts: 19
Joined: Thu Jul 24, 2008 3:35 am
Location: Chennai,Tamilnadu,India

Delete a file...

Post 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....
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: Delete a file...

Post by WebbieDave »

Use readdir to loop through the directory contents, checking if filename starts with hari using strpos.
php000developer
Forum Newbie
Posts: 4
Joined: Fri Jul 25, 2008 6:24 am

Re: Delete a file...

Post 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!";
?>
panprasath
Forum Newbie
Posts: 19
Joined: Thu Jul 24, 2008 3:35 am
Location: Chennai,Tamilnadu,India

Re: Delete a file...

Post by panprasath »

Thank you for your help...
Post Reply