如何从我的 MySql 数据库中删除 PDF 名称和从 PHP 中删除 PDF 文件夹

问题描述 投票:0回答:1

我尝试制作一个可以查看、下载和删除PDF文件的PHP。查看和下载工作正常,但删除却不行(我希望在删除文件和数据库时都删除)。

Here is my table (simpanfile) in database :

Kode : for file id in database as primary key
Nama_File : the name that user input manually when upload file
Nama_Asli_File : the name that follow the real name of the file.
Folder_Berkas : the folder path for the PDF file. 

这是我的 Index.php,用于查看、下载和删除

    <a href="View.php?url=<?php echo $row['Folder_Berkas']; ?>">Lihat</a> <c> - </c>                            
    <a href="DownloadFile.php?url=<?php echo $row['Folder_Berkas']; ?>">Unduh</a> <c> - </c>    
    <a href="Hapus.php?url=<?php echo $row['Folder_Berkas']; ?>">Hapus</a>

所以基本上,我的PHP调用上传的文件的文件夹路径来查看和下载。我尝试使用此代码删除文件,但它不起作用。


    include "Koneksi.php";
    $edit=$_GET['url'];
    $sql=sprintf("delete from simpanfile where Folder_Berkas=",$edit);
    unlink($_GET["url"]);
    header("location:Index.php?");

知道如何直接从我的 PHP 中删除数据库和文件中的信息吗?我是新手,请原谅我糟糕的英语。

php mysql pdf xampp
1个回答
0
投票
$removeFileResult=unlink("pathtofile/".$filename);
if($removeFileResult){  
  echo "Drop row or empty column of file using related query";  
  // delete from tbl_images where filename=?, $filename
}else{  
  echo "try again or send error back to frontend. because file is still in the folder!";    
}  

但是我发现您要删除的内容似乎是一个文件夹。您不使用文件夹的取消链接。只需在代码中将 unlink() 替换为 rmdir()

© www.soinside.com 2019 - 2024. All rights reserved.