如何在Windows 7中使用unlink?

时间:2012-09-29 07:20:48

标签: php windows-7

在Win 7机器中使用unlink时出现问题。这是我在getFile.php中的代码

$file_name = 'C:\xampp\htdocs\fw\tmp\my_file.php';
$myfile = fopen($file_name , 'a');
unlink(''.$file_name );

每次执行代码时,都会收到错误消息

警告:取消链接(C:\ xampp \ htdocs \ fw \ tmp \ my_file.php)[function.unlink]:C:\ xampp \ htdocs \ fw \ libraries \ getFile.php中的权限被拒绝79

有人有解决方案吗?

之前感谢,

3 个答案:

答案 0 :(得分:12)

您无法删除已打开的文件

$file_name = 'C:\xampp\htdocs\fw\tmp\my_file.php';
$myfile = fopen($file_name , 'a');
..
fclose($myfiles);
..
unlink(''.$file_name );

答案 1 :(得分:1)

$file_name = 'C:\xampp\htdocs\fw\tmp\my_file.php';
$myfile = fopen($file_name , 'a');
unlink(''.$file_name );

您无法使用此

删除文件

首先你需要关闭那个文件

使用

fclose($myfiles);

并使用

$filename="myfile.php";  
unlink("../../../../"$filename);

您无法使用c:\xamp....http:\\file\files.php

删除

答案 2 :(得分:0)

我正在使用Windows 10和xampp,这适用于,

unlink(pathinfo(realpath($file_name), PATHINFO_DIRNAME).DIRECTORY_SEPARATOR . $file_name);