Search code examples
phpdownloadunlink

php unlink file renovated


I want to delete with php (unlink function) file which is out of webroot. my web root is in

C:\server\webroot\project\... in webroot I have folder named project and in there I have .php files.

whats about files directory. it is situated C:\server\mp3_files...

Also I've created in httpd.conf Alias("mp3") of mp3_files directory


I am writing this script in C:\server\webroot\project\test.php

script is like so =>

function delete($filename){
if (unlink("/mp3/" . $filename)){
    echo "Deleted";
} else {
    echo "No";
}
 }
delete("file.txt");

this script gives me in php-errors => PHP-WARNING No such file or directory

also I have in (test.php) html form this =>

<a href="/mp3/file.txt">Download</a>

And this works (It opens this file.txt)

So I'm wondered why can't delete with marked function "delete($filename)" ?


Solution

  • "/mp3/" . $filename is an absolute filepath, not relative to the webserver root, so it's assuming that you have an mp3 directory under your filesystem root when you should be looking under /server/mp3

    EDIT

    And is it /server/mp3 or /server/mp3_files

    your post seems to contradict your code