Reputation: 580
My server stores 2 video files and 2 database records.
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,
Original video is stored in original and 480p video is store in original\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
Upvotes: 1
Views: 60
Reputation: 720
$deleteOrigVideo and $delete480pVideo are not strings; They are MySQLi query result objects.
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.
Upvotes: 3