Deleting file from folder

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
captain_scarlet87
Forum Newbie
Posts: 7
Joined: Thu Mar 11, 2010 3:27 pm

Deleting file from folder

Post by captain_scarlet87 »

Hi,

I'm currently trying to delete a file from a folder however I am getting these errors:

Warning: unlink(testflash.flv) [function.unlink]: No such file or directory in C:\wamp\www\html\delete_video.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\html\delete_video.php:6) in C:\wamp\www\html\delete_video.php on line 8

Would anyone kindly point out where I have made a mistake? Thanks.

view_videos(admin).php:

Code: Select all

<?php
  $current_dir = "includes/videos/";    // Location to read files from.
  $dir = opendir($current_dir);        // Opens the directory.
 
  echo ("<p><h1>Video Tutorials:</h1></p><hr><br />");
  while ($file = readdir($dir))            // while loop
    {
    $parts = explode(".", $file);                    // pull apart the name and dissect by period
    if (is_array($parts) && count($parts) > 1) {    // does the dissected array have more than one part
        $extension = end($parts);        // set to we can see last file extension
        if ($extension == "flv"){    // Set allowable file extensions.
             echo "<table><tr><td><a href=video_player.php?video=$file> $file </a><br /></td>";    // Link to location of video.
             echo "<td><a href=delete_video.php?video=$file> Delete </a><br /></td></tr></table>";
        }
       }
    }
  echo "<hr><br />";
  closedir($dir);        // Close the directory.
?>
</body>
</html>
delete_video.php:

Code: Select all

<?php
    //delete_video.php
 
    $file = $_GET['video'];
 
    unlink($file);
 
    header("location:view_videos(admin).php");
?>
Post Reply