删除Web文件夹中的文件无法正常工作[关闭]

删除Web文件夹中的文件无法正常工作[关闭]

问题描述:

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!

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

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