php - 使用 php 代码从主机中删除 jpg 文件
问题描述
在这个 php 中,我想获取一个“ID”并从数据库中找到该 ID 的 Img1。(Img1 的 url 存储在数据库中)。然后删除这个文件。但 img1 没有删除
function delete(){
$connection = connectToDatabase();
$ID = $_REQUEST['ID'];
if($ID!==""){
$result1 = mysqli_query($connection,"select Img1 from banners where ID='$ID' ");
$row = mysqli_fetch_array($result1);
$namefile1 = $row[0];//(in $namefile1 the url address of img1 is saved like this:http://bestabsd.com/bestfile/pics/jan18-11-28-20-46-36.jpg)
$files = glob($namefile1);
foreach($files as $file){
if(is_file($file))
unlink($file);}
mysqli_close($connection);
}
解决方案
编辑:我将我的代码编辑为新的以创建路径,但 jpg 尚未删除....
function delete(){
$connection = connectToDatabase();
$ID = $_REQUEST['ID'];
if($ID!==""){
$result1 = mysqli_query($connection,"select Img1 from banners where ID='$ID' ");
$row = mysqli_fetch_array($result1);
$namefile1 = $row[0];
$namefile11=str_replace("http://bestabsd.com/bestfile/pics/", "", $namefile1);
$base_directory = '/home/bestabsd/public_html/bestfile/pics/';
unlink($base_directory.$namefile11);
mysqli_close($connection);
}else {
print "null";
}
推荐阅读
- c# - WPF 文本框焦点()
- css - 将鼠标悬停在子菜单上时保持父菜单突出显示
- powershell - 在 PowerShell 中将环境变量设置为空字符串
- keras - 分数 maxpool 使运行时在 google colab 上死掉
- timer - STM32 上 Systick 定时器的功耗
- jdbc - 使用 Impala 的 PreparedStatement:无法识别“?”附近的输入
- docker - Visual Studion 2017 预览版 5.0
- sql-server - 错误选择 xml 列 SQL Server
- c - Eclipse 控制台在程序终止之前不打印
- ios - TextInput 垂直对齐