problem with deleting files from folder
Posted: Thu Dec 24, 2009 3:25 pm
I have list with files like this:
As you can see there is a delete button and the code for deleting a file is wrong. Here is the code:
Can you please help me. Am I missing somethig?? The file has to be deleted from the uploads folder
Thanks in advance
Code: Select all
$query= "SELECT file.fileID
, file.NAME
, file.size
, file.create_date
, file.user_ID
, file.br_downloads FROM file WHERE file.user_ID = '".mysql_real_escape_string($_SESSION['user_ID'])."'
AND name LIKE '%$trimmed%' ORDER BY $sort $sort_order limit $eu, $limit";
$result=mysql_query($query);
echo mysql_error();
while ($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr align='left' bgcolor='$row[colourcode]'>";
foreach ($rows as $data)
{
echo "<td align='left' font size='2' face='Verdana, Arial, Helvetica, sans-serif' color='#006699'>". $data . "</td>";
}
echo "<td style='width: 300px'>
<form method=post action='delete.php'>
<input name='delete' type='submit' value='Delete' style='width: 92px' /></td>
</form>";
}Code: Select all
if (isset($_GET['name']))
{
$fileID=$_GET['name'];//id-to na file-ot
$username=$_SESSION['user_ID'];
//proveruvame dali fajlot e downloaduvan
$sql="SELECT br_downloads FROM file WHERE fileID='$fileID'";
$download=@mysql_query($sql);
$counter=@mysql_fetch_array($download,MYSQL_ASSOC);
// ako ne e downloaduvan dozvoli da se izbrise
if ($counter['br_downloads'] == 0)
{
$counter=$counter['counter'];
//za da ja dobijam ekstenzijata
$query="SELECT * FROM file WHERE fileID='".$fileID."'";
$result=mysql_query($query);
$name=mysql_fetch_array($result, MYSQL_ASSOC);
$filename = $name['name'];
$ext = substr($filename, strrpos($filename, '.') + 1);
$path="C:/Documents and Settings/PC/My Documents/Visual Studio 2008/Projects/filemanager/filemanager/uploads/";
$filepath=$path.$fileID/*.".".$ext*/;
// potoa od baza gi brisam podatocite
$sql="DELETE FROM file WHERE fileID='".$fileID."'";
$result=@mysql_query($sql);
// go brisam fajlot od folderot
if(unlink($filepath))
{
$success="You deleted the file successfully.";
}
}
else
{
$message="<tr colspan='4'><td>You can not delete this file.</td></tr>";
header("Location: my_profile.php?$message");
}
}Thanks in advance