我的服务器存储2个视频文件和2个数据库记录。
如果用户选择删除文件,我试图从我的数据库中删除它。
要从数据库中删除的脚本:
$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."'");
使用此脚本检索文件路径:
$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."'");
删除文件:
unlink($deleteOrigVideo);
unlink($delete480pVideo);
取消关联部分无效。我得到unlink()期望参数1是一个有效的路径,
原始视频存储在原始中,480p视频存储在原始\ 480p
中 var_dump($deleteOrigVideo, $delete480pVideo);
输出:
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
答案 0 :(得分:3)
$ deleteOrigVideo和$ delete480pVideo不是字符串;它们是MySQLi查询结果对象。
你会想做这样的事情(重复第二个视频):
if($deleteOrigVideo) {
while ($videoEntry = $deleteOrigVideo->fetch_assoc()) {
unlink($videoEntry['video_link']);
}
}
我假设“$ videoEntry ['video_link']”返回的路径指向您想要的路径。