从php文件夹中删除图像 使用select query获取文件名时使用fileid。然后执行delete语句 <?php include ('config.php'); echo '<script>confirm("Are you sure?");</script>'; if(isset($_GET['fileid'])) { $fileid = $_GET['fileid']; $target_dir = "img/"; $target_file = $target_dir .$_GET['fileid']; $query = "DELETE FROM file_info WHERE fileid='$fileid'"; $result = mysqli_query($conn,$query); $row = mysqli_fetch_array($result); $path = "img/".$row['filename']; if($result) { unlink($path); echo'<script>window.location ="table.php";</script>'; } else { echo'<script>window.location ="table.php";</script>'; } } ?>
打印$result并交叉检查是否能够到达if()块内部。另外,从获取值的位置从php文件夹中删除图像 使用select query获取文件名时使用fileid。然后执行delete语句 <?php include ('config.php'); echo '<script>confirm("Are you sure?");</script>'; if(isset($_GET['fileid'])) { $fileid = $_GET['fileid']; $target_dir = "img/"; $target_file = $target_dir .$_GET['fileid']; $query = "DELETE FROM file_info WHERE fileid='$fileid'"; $result = mysqli_query($conn,$query); $row = mysqli_fetch_array($result); $path = "img/".$row['filename']; if($result) { unlink($path); echo'<script>window.location ="table.php";</script>'; } else { echo'<script>window.location ="table.php";</script>'; } } ?>,php,Php,打印$result并交叉检查是否能够到达if()块内部。另外,从获取值的位置$row['filename']首先使用选择查询选择值。更改删除查询以选择并给出$row['filename']的绝对路径和获取关联数组。 代码 <?php $path = "img/".$row['filename']; if( file_exists ( $path )) unlink( $path); else echo "file not found"; ?> 删除查询不从数据库获取
$row['filename']
首先使用选择查询选择值。更改删除查询以选择并给出$row['filename']的绝对路径和获取关联数组。
代码
<?php
$path = "img/".$row['filename'];
if( file_exists ( $path ))
unlink( $path);
else
echo "file not found";
?>
删除查询不从数据库获取数据!!相反,您需要使用选择查询!!在删除过程中,您将不会获得记录。您需要先获取记录,然后删除记录。因此,首先使用
SELECT
语句,然后选择DELETE
语句。您还应该小心地将$\u GET参数直接传递给SQL查询。您可以轻松地将1或1=1
作为fileid
传递,这将删除文件信息表中的所有记录。如果数据库中的fileid
字段是整数,则使用准备好的语句或typecastfileid
进行int运算
$fileid = $_GET['fileid'];
$target_dir = "img/";
$target_file = $target_dir .$_GET['fileid'];
$query = "SELECT filename FROM file_info WHERE fileid='$fileid'";
$result = mysqli_query($conn,$query);
$row = mysqli_fetch_assoc($result); // And fetch assoc array
$path = "c:\project\img\".$row['filename'];