有没有可能在PHP中更新个人资料图片,并从文件夹中删除当前的图片以及数据库中的链接?
如果是,请帮助我:我设法从数据库中删除了链接,但文件夹中的图片仍然存在。
发布于 2013-02-07 16:29:15
假设您有一个名为Images的文件夹,您在其中上传了图片,因此在该文件夹中有一个名为test.jpg的图像。此代码将删除文件夹中的图像。@David Rabinowitz感谢你给了他一个使用数据库的很好的答案,但我也试图给他第二个不使用数据库的例子,也许这也会对他有帮助
<?php
$file ="test.jpg";
$filedel="images/".$file;
if(file_exists($file)){
echo "file exits";
unlink($filedel);
else{
echo "the file you want to delete does nto exist ";
}
?>发布于 2012-12-31 21:27:01
使用unlink函数。
//before deleting the path from database, get it in one variable using php
$filename = path from database;
unlink($filename);发布于 2012-12-31 21:30:21
PHP unlink函数用于从目录中删除已有的文件
$filename = 'define file name here with proper path';
unlink($filename); https://stackoverflow.com/questions/14102176
复制相似问题