2

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

1
  • How are you calling this? What are your values for $_GET["file_path"] and $data? Commented Jan 19, 2012 at 4:19

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank's much very much that was what was causing it.
0

Try to remove the trailing slash.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.