问题
I have a problem when using unlink in my Win 7 machine. This is my code in getFile.php
$file_name = 'C:\xampp\htdocs\fw\tmp\my_file.php';
$myfile = fopen($file_name , 'a');
unlink(''.$file_name );
everytime I execute the code, i get an error message
Warning: unlink(C:\xampp\htdocs\fw\tmp\my_file.php) [function.unlink]: Permission denied in C:\xampp\htdocs\fw\libraries\getFile.php on line 79
Anybody has a solution ?
Thanks before,
回答1:
You cann't remove files that are opened
$file_name = 'C:\xampp\htdocs\fw\tmp\my_file.php';
$myfile = fopen($file_name , 'a');
..
fclose($myfiles);
..
unlink(''.$file_name );
回答2:
$file_name = 'C:\xampp\htdocs\fw\tmp\my_file.php';
$myfile = fopen($file_name , 'a');
unlink(''.$file_name );
You cannot delete file using this
first you need to close that file
using
fclose($myfiles);
and use
$filename="myfile.php";
unlink("../../../../"$filename);
you cannot delete using c:\xamp....
or http:\\file\files.php
回答3:
i am using windows 10 and xampp , this worked for ,
unlink(pathinfo(realpath($file_name), PATHINFO_DIRNAME).DIRECTORY_SEPARATOR . $file_name);
来源:https://stackoverflow.com/questions/12650777/how-to-use-unlink-in-windows-7