如何在PHP中取消链接图像 [英] How to unlink image in php

查看:95
本文介绍了如何在PHP中取消链接图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像上传到服务器,并将路径保存在数据库中.现在我想删除该记录以及具有该记录的图像 我的代码是

i upload image to the server and save the path in data base. Now i want to delete that record and also the image with that record my code is

$id=$_GET['id'];
$select=mysql_query("select image from table_name where question_id='$id'");
$image=mysql_fetch_array($select);
@unlink($image['image']);
$result=mysql_query("delete from table_name where question_id='$id'");

当我回显$ image ['image'];时这会给我

when i echo $image['image']; this will give me

http://www.example.com/folder/images/image_name.jpeg

记录已成功删除,但映像仍保留在服务器上.

The record is deleted successfully but the image remains there on server.

推荐答案

您将必须使用服务器上的路径来删除图像,而不是url.

You'll have to use the path on your server to delete the image, not the url.

unlink('/var/www/test/folder/images/image_name.jpeg'); // correct

您应该在unlink()之前删除@,在这种情况下,您会看到错误消息,提示找不到文件"或类似的内容.

you should remove the @ before unlink(), in that case you would have seen the error-message saying "file not found" or something like that.

这篇关于如何在PHP中取消链接图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆