[英]Deleting files from server using PHP
My server stores 2 video files and 2 database records. 我的服务器存储2个视频文件和2个数据库记录。
I am trying to delete it from my database if user chooses to delete the files. 如果用户选择删除文件,我试图从我的数据库中删除它。
Script to delete from database: 要从数据库中删除的脚本:
$result = mysqli_query($db_connection , "DELETE FROM `viewvideo` WHERE `video_id`='".$video_id."'");
$result2 = mysqli_query($db_connection , "DELETE FROM `video480p` WHERE `video_id`='".$video_id."'");
Using this script to retrieve the file path: 使用此脚本检索文件路径:
$deleteOrigVideo = mysqli_query($db_connection, "Select video_link FROM viewvideo WHERE `video_id`='".$video_id."'");
$delete480pVideo = mysqli_query($db_connection, "Select video_link FROM video480p WHERE `video_id`='".$video_id."'");
Delete Files: 删除文件:
unlink($deleteOrigVideo);
unlink($delete480pVideo);
The unlink part is not working. 取消链接部分无法正常工作。 I am getting unlink() expects parameter 1 to be a valid path,
我得到unlink()期望参数1是一个有效的路径,
Original video is stored in original and 480p video is store in original\\480p 原始视频被储存在原有的和480p的视频是在原\\ 480P店
var_dump($deleteOrigVideo, $delete480pVideo);
Output: 输出:
object(mysqli_result)[2]
public 'current_field' => null
public 'field_count' => null
public 'lengths' => null
public 'num_rows' => null
public 'type' => null
object(mysqli_result)[3]
public 'current_field' => null
public 'field_count' => null
public 'lengths' => null
public 'num_rows' => null
public 'type' => null
$deleteOrigVideo and $delete480pVideo are not strings; $ deleteOrigVideo和$ delete480pVideo不是字符串; They are MySQLi query result objects .
它们是MySQLi查询结果对象 。
You'll want to do something like this (repeat for the second video): 你会想做这样的事情(重复第二个视频):
if($deleteOrigVideo) {
while ($videoEntry = $deleteOrigVideo->fetch_assoc()) {
unlink($videoEntry['video_link']);
}
}
I'm assuming the paths returned by "$videoEntry['video_link']" point where you want them to. 我假设“$ videoEntry ['video_link']”返回的路径指向您想要的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.