将 unlink() 与 sql delete 结合起来
我设置了一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需在循环中使用
Unlink()
即可:我使用了
If
因为如果文件从数据库中删除成功,那么它就会从服务器中删除。另外,如果您已按文件名将文件移动到文件夹中,则首先通过
$id
从数据库获取有关文件的信息,然后使用它希望
它会对您有所帮助。
Just use
Unlink()
with in loop like :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 useinstead
Hope it will help you.
如果图像根据 ID 命名:
请确保在查询或 unlink 语句中使用 $id 之前正确转义它。
If the images are named in accordance with the ID:
Be sure to properly escape $id before using it in your query or in the unlink statement.
那么,文件存储在服务器的哪里呢?它们是如何存储的?只需使用指向图像存储位置的文件路径调用
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.