将 unlink() 与 sql delete 结合起来

发布于 2024-11-17 09:38:55 字数 485 浏览 2 评论 0原文

我设置了一个简单的 while 循环,它返回表中的所有图像及其各自的标题和描述,以便用户可以相应地更新每个图像的详细信息。

返回的图像带有一个复选框,允许用户根据 php 代码删除图像

if($_POST['doDelete'] == 'Delete') {

if(!empty($_POST['u'])) {
    foreach ($_POST['u'] as $uid) {
        $id = filter($uid);
        mysql_query("delete from landscape where id='$id'");
    }
 }
 $ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str'];;

 header("Location: $ret");
 exit();
}

如何将 unlink() 函数合并到页面中,以便该文件也从服务器中删除?

I have setup a simple while loop which returns all images in a table along with their respective title and description so that users can update the details accordingly for each image.

The images are returned with a checkbox which allows user to delete images as per php code

if($_POST['doDelete'] == 'Delete') {

if(!empty($_POST['u'])) {
    foreach ($_POST['u'] as $uid) {
        $id = filter($uid);
        mysql_query("delete from landscape where id='$id'");
    }
 }
 $ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str'];;

 header("Location: $ret");
 exit();
}

How do I incorporate the unlink() function into the page so that the file is also removed from the server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

口干舌燥 2024-11-24 09:38:55

只需在循环中使用 Unlink() 即可:

foreach ($_POST['u'] as $uid) {
    $id = filter($uid);
    if(mysql_query("delete from landscape where id='$id'")){
    unlink( '/path/to/images/' . $id);
    }
}

我使用了 If 因为如果文件从数据库中删除成功,那么它就会从服务器中删除。
另外,如果您已按文件名将文件移动到文件夹中,则首先通过 $id 从数据库获取有关文件的信息,然后使用它

unlink( '/path/to/images/' . $file_name);

希望

unlink( '/path/to/images/' . $id);

它会对您有所帮助。

Just use Unlink() with in loop like :

foreach ($_POST['u'] as $uid) {
    $id = filter($uid);
    if(mysql_query("delete from landscape where id='$id'")){
    unlink( '/path/to/images/' . $id);
    }
}

I have used If because if the file deleted successfully from the database only then it will be deleted from the server.
Also If you have moved the file into folder by the name of file then First get information about file from database by $id and then use

unlink( '/path/to/images/' . $file_name);

instead

unlink( '/path/to/images/' . $id);

Hope it will help you.

梦境 2024-11-24 09:38:55

如果图像根据 ID 命名:

foreach ($_POST['u'] as $uid) {
    $id = filter($uid);
    mysql_query("delete from landscape where id='$id'");
    unlink( '/path/to/images/' . $id);
}

请确保在查询或 unlink 语句中使用 $id 之前正确转义它。

If the images are named in accordance with the ID:

foreach ($_POST['u'] as $uid) {
    $id = filter($uid);
    mysql_query("delete from landscape where id='$id'");
    unlink( '/path/to/images/' . $id);
}

Be sure to properly escape $id before using it in your query or in the unlink statement.

花开半夏魅人心 2024-11-24 09:38:55

那么,文件存储在服务器的哪里呢?它们是如何存储的?只需使用指向图像存储位置的文件路径调用 unlink 即可。

Well, where are the files stored on the server? How are they stored? Just call unlink with the file path that leads to where the image is stored.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文