问题
Source Code (Código):
$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);
and the file is not deleted, I also tried using file_exists
to check the file before, and the return is: false
.
The file_put_contents
creates the file correctly (checked), even with the correct content. I can access the file through file_get_contents
, but in time to delete or verify the existence get failure. Anyone have a clue?
The total size of $path
is 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. I can delete some, others not, issuing the warning described above. Can it be any character that is not to unlink() does not accept? I have some escape reserved characters such as /\?%*:|"<>. http://en.wikipedia.org/wiki/Filename
I tried using hash (sha1, sha256 and sha512) instead of base64_encode, but the error persists.
Thank you.
ORIGINAL LANGUAGE:PT-BR:
No código acima obtenho o alerta No such file or directory
em unlink($path);
e o arquivo não é excluído, eu também tentei usar file_exists
para verificar a existência do arquivo antes, e o retorno é: false
.
O file_put_contents
cria o arquivo corretamente (verificado), inclusive com o conteúdo correto. Eu também consigo acessar o arquivo através de file_get_contents
, mas na hora de excluir ou verificar a existência obtenho insucesso. Alguém tem uma dica?
O tamanho total de $path
é 241
.
O problema parecer mais delicado. Pois o nome do arquivo é formado por um base64_encode, o nome do arquivo muda frequentemente, e eu tenho cerca de 10 arquivos por execução. Alguns deles consigo deletar, outros não, emitindo o alerta descrito acima. Será que pode ser algum caractere que não que unlink() não aceita? Eu já escapo alguns caracteres reservados, como /\?%*:|"<>.http://en.wikipedia.org/wiki/Filename
Eu tentei usar hash (sha1, sha256 e sha512) no lugar de base64_encode, mas o erro persiste.
Obrigado.
回答1:
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:
<?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);
?>
回答2:
try
$path ="F:/www/__DADOS__/__SESSAO/__9987f2bfdfb80bce8fd72402887bb2c50a433ae0__E6nDSMnD7TCY5#47$BNCx0e#47$r#47$ByZJvcyMIazXSYWBWBXN5lgdZOd3Ps#47$ROrVSPl7QVQaCqfa2WezCauk#47$LVFyhgw==.meudominio.com.sessid"
来源:https://stackoverflow.com/questions/18455188/php-file-exists-and-unlink-doesnt-work