Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从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 - Fatal编程技术网

从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文件夹中删除图像 使用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"; ?> 删除查询不从数据库获取

打印$result并交叉检查是否能够到达if()块内部。另外,从获取值的位置
$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
字段是整数,则使用准备好的语句或typecast
fileid
进行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'];