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!
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");
}
}
Can you please help me. Am I missing somethig?? The file has to be deleted from the uploads folder
Thanks in advance
Your first script has a form that declares that the method to be used is POST, but it contains nothing but a Submit button. Your second script is looking for a $GET variable, which is looking for the variable in the URL string. So your 2 scripts are not communicating with each other. What is your intention? Do you want the user to select one of the files listed there, or is the purpose to delete ALL of the files listed? I can't really tell from your code what you want to do.
my intention is to delete one of the files in the list and I don't know how to do it. Actually i tried something, but I am not sure how to access to the file a want to delete and to connect the 2 scripts
That's the end of the logic in the first script. That will display the data from each file selected, plus a button that says "DELETE" and when it is clicked next to one of the entries, it will call the delete.php script with the fileID of that file as the $_GET parameter, ID.
// your MySQL connect code
if (isset($_GET['ID']))
{
$fileID=mysql_real_escape_string($_GET['ID']);
$sql="DELETE FROM file WHERE fileID='$fileID'";
mysql_query($sql) or die(mysql_error());
echo "File was successfully deleted."
}