[英]PHP file_exists and unlink doesn't work (“No such file or directory”)
$path = "F:/www/__DADOS__/__SESSAO/__9987f2bfdfb80bce8fd72402887bb2c50a433ae0__E6nDSMnD7TCY5#47$BNCx0e#47$r#47$ByZJvcyMIazXSYWBWBXN5lgdZOd3Ps#47$ROrVSPl7QVQaCqfa2WezCauk#47$LVFyhgw==.meudominio.com.sessid"
file_put_contents($path, $texto);
unlink($path);
In the above code I get the warning No such file or directory
in unlink($ path);
在上面的代码中,我收到警告在unlink($ path);
No such file or directory
unlink($ path);
and the file is not deleted, I also tried using file_exists
to check the file before, and the return is: false
.而且文件没有删除,之前我也试过用file_exists
检查文件,返回: false
。
The file_put_contents
creates the file correctly (checked), even with the correct content. file_put_contents
正确创建文件(已检查),即使内容正确。 I can access the file through file_get_contents
, but in time to delete or verify the existence get failure.我可以通过file_get_contents
访问文件,但及时删除或验证存在获取失败。 Anyone have a clue?有人有线索吗?
The total size of $path
is 241
. $path
的总大小为241
。
The problem seems more delicate.问题似乎更加微妙。 The file name is formed by an base64_encode , the filename changes often, and I have about 10 files per execution.文件名由base64_encode 组成,文件名经常更改,每次执行我大约有 10 个文件。 I can delete some, others not, issuing the warning described above.我可以删除一些,其他人不能,发出上述警告。 Can it be any character that is not to unlink() does not accept?可以是不是unlink()不接受的任何字符吗? I have some escape reserved characters such as /\\?%*:|"<> . http://en.wikipedia.org/wiki/Filename我有一些转义保留字符,例如/\\?%*:|"<> 。http://en.wikipedia.org/wiki/Filename
I tried using hash (sha1, sha256 and sha512) instead of base64_encode, but the error persists.我尝试使用哈希(sha1、sha256 和 sha512)而不是 base64_encode,但错误仍然存在。
Since you are using /
inside of " "
so /
char is not a normal character and it's usually used to escape special characters ( wen used inside of double quotation marks ), but if you want to ignore any /
inside of your string value definition just use //
so the first forward slash will escape the second one and PHP
will treat them as one slash but don't forget to escape dollar sign ( $
) as well and all special chars or change your quotations from "
to '
then you don't have to change anything inside your string value:由于您在" "
内部使用/
,所以/
char 不是普通字符,它通常用于转义特殊字符(在双引号内使用 wen ),但是如果您想忽略字符串值定义中的任何/
使用//
所以第一个正斜杠将转义第二个, PHP
会将它们视为一个斜杠,但不要忘记转义美元符号 ( $
) 以及所有特殊字符或将引号从"
更改为'
然后你不不必更改字符串值中的任何内容:
<?php
$path = 'F:/www/__DADOS__/__SESSAO/__9987f2bfdfb80bce8fd72402887bb2c50a433ae0__E6nDSMnD7TCY5#47$BNCx0e#47$r#47$ByZJvcyMIazXSYWBWBXN5lgdZOd3Ps#47$ROrVSPl7QVQaCqfa2WezCauk#47$LVFyhgw==.meudominio.com.sessid';
//OR
$path = "F://www//__DADOS__//__SESSAO//__9987f2bfdfb80bce8fd72402887bb2c50a433ae0__E6nDSMnD7TCY5#47/$BNCx0e#47/$r#47/$ByZJvcyMIazXSYWBWBXN5lgdZOd3Ps#47/$ROrVSPl7QVQaCqfa2WezCauk#47/$LVFyhgw==.meudominio.com.sessid";
echo file_exists($path);//will return 1
//unlink($path);
?>
尝试
$path ="F:/www/__DADOS__/__SESSAO/__9987f2bfdfb80bce8fd72402887bb2c50a433ae0__E6nDSMnD7TCY5#47$BNCx0e#47$r#47$ByZJvcyMIazXSYWBWBXN5lgdZOd3Ps#47$ROrVSPl7QVQaCqfa2WezCauk#47$LVFyhgw==.meudominio.com.sessid"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.