5

I've such a situation. I want to delete .wav file which is out of webroot directory , but I've defined in httpd.conf (apache) alias of this directory like "mp3" . this is working nicely, because I can download file from webroot and so on ... But I want to delete it also which I can't do. I have PHP script like this =>

class Delete{
   public function del_directory_record($filename){
    if (unlink("/mp3/$filename")){
        return true;
    }
}
}

 $new = new Delete();
 $new->del_directory_record("file.wav");

In php-errors it gives me "PHP Warning => No such file or directory" I'm interested in what I'm doing wrong ?

It still doesn't work ...

I've at C:\server\webroot... and I have directory mp3_files at C:\server\mp3_files In httpd.conf I've written

Alias /mp3/ "C:/server/mp3_files/"
<Directory "C:/server/mp3_files/">
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
DaHaKa
  • 161
  • 1
  • 1
  • 6

2 Answers2

10

I think you meant to do this relative to your DOCUMENT_ROOT:

class Delete {
   public function del_directory_record($filename) {
      return unlink($_SERVER['DOCUMENT_ROOT'] . "/mp3/$filename");
   }
}

$new = new Delete();
$new->del_directory_record("file.wav");

Just use this standalone function, it will do just fine. No need to create an object or class.

function delete_directory_record($filename) {
   return unlink($_SERVER['DOCUMENT_ROOT'] . "/mp3/$filename");
}
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
  • Thanks for helping :) . I know that only this script don't belong to class , but it is only part class script ... – DaHaKa Jan 04 '12 at 13:19
  • It still doesn't work :(, Now it writes me the same No such file or directory. I can't guess whats wrong with it – DaHaKa Jan 04 '12 at 13:31
  • @DaHaKa Where on your filesystem does "file.wav" live relative to your web server's document root? – Jacob Relkin Jan 04 '12 at 13:48
  • In webroot directory I've not problem, everthing working nicely, but outside of webroot it doesn't – DaHaKa Jan 04 '12 at 14:00
-3

Try

if (unlink("/mp3/".$filename)){
        return true;
    }

or what Jacob Relkin wrote with document root

Snake Eyes
  • 16,287
  • 34
  • 113
  • 221