Petty_Crim
Petty_Crim

Reputation: 441

PHP Unlinking File - Directory Issue

I am trying to unlink a file but the PHP unlink function seems to refer to the directory of the script file I am using rather then where the file is.

I am using change directory (chdir) to change the directory and yet this is seemingly having no effect:

chdir("themes");
    $file_path = getcwd()."/".$_GET["file_path"]."/";
    $deleted_file=$file_path.$data["file_name"];
    $fh = fopen($deleted_file, 'w') or die("Can't open file");
    fclose($fh);
    unlink($deleted_file);

The error I get is the following: Warning: fopen(/home/mow/public_html/mysite/themes/_default/admin/testfile.php/): failed to open stream: No such file or directory in /home/mow/public_html/mysite/themes/_default/admin/file_manager.php on line 223

Upvotes: 2

Views: 455

Answers (2)

Rannnn
Rannnn

Reputation: 582

Try to remove the trailing slash.

BTW: Why don't pass the path directly to unlink instead of using chdir then getcwd?

Upvotes: 0

Borealid
Borealid

Reputation: 98459

It looks to me like your 'file_name' GET variable ends with a slash. Try ensuring that isn't the case.

NB: Make really, really, really sure that nobody you don't completely trust will have the ability to access this script.

Upvotes: 1

Related Questions