-2

Im trying to delete irrelevant files from the web folder and the script aint working.

Here is the code:

<?php

    if(isset($_REQUEST['delete_file'])){

        if(isset($_GET['file_id'])){

$file_id = mysql_real_escape_string(strip_tags($_GET['file_id']));

    $file_info_query = @mysql_query("select * from video where id='$file_id'");
    $file_info_row = @mysql_fetch_assoc($file_info_query);
    $filename = $file_info_row['filename'];

        $path = $_SERVER['DOCUMENT_ROOT'].'/test2/video/';

        $file_path = $path;
        $file_path .= $filename;

            if(unlink($file_path))
            {
            echo "<p>File deleted successfully.</p> ";
            }
            else
            {
            echo "<p>Unable to delete file. Try again shortly.</p> ";
            }       

        }

    }



    ?>

Would be grateful getting this to work...Thank!

Sms
  • 147
  • 1
  • 9
  • 20
  • You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Feb 04 '13 at 12:07
  • 1
    If it isn't working, why are you **suppressing all the errors** that might tell you why?! (by littering `@`s across the code base) – Quentin Feb 04 '13 at 12:08

1 Answers1

1

Unlink function expects the complete server path of file. Please change your $path value to this one:

$path = $_SERVER['DOCUMENT_ROOT'].'/test2/video/';
Code Prank
  • 4,209
  • 5
  • 31
  • 47