How to use unlink in Windows 7?

流过昼夜 提交于 2019-12-11 01:15:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!