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 on line 没有此类文件或目录在第行
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.
Try to remove the trailing slash.
BTW: Why don't pass the path directly to unlink
instead of using chdir
then getcwd
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.