php unlink No error 警告

qii 发布于 2013/08/06 09:46
阅读 323
收藏 0
PHP

win7,apache2.2,php5.2

使用file_exists检查文件,返回true

使用unlink函数删除文件发生错误,下面是返回信息。

<b>Warning</b>: unlink() [<a href='function.unlink'>function.unlink</a>]: No error in <b>E:\workspace\uploadify\upload_ajax.php</b> on line <b>12</b><br />

请问这是怎么回事。

加载中
0
YY-OiCiU
YY-OiCiU

引用来自“qii”的答案

引用来自“YY-OiCiU”的答案

unlink传递绝对路径试试。还有检查下文件最终是否删除了。= = 最后,用@来抑制警告。

文件没有被删除,用的是绝对路径.

我没遇过类似的问题,网上有文章提到,如果你已经打开了那个文件的句柄,那么unlink之前需要释放句柄。。。

http://php.net/manual/en/function.unlink.php

I have been working on some little tryout where a backup file was created before modifying the main textfile. Then when an error is thrown, the main file will be deleted (unlinked) and the backup file is returned instead.

Though, I have been breaking my head for about an hour on why I couldn't get my persmissions right to unlink the main file.

Finally I knew what was wrong: because I was working on the file and hadn't yet closed the file, it was still in use and ofcourse couldn't be deleted :)

So I thought of mentoining this here, to avoid others of making the same mistake:

<?php
// First close the file
fclose($fp);

// Then unlink :)
unlink($somefile);
?>

0
YY-OiCiU
YY-OiCiU

unlink传递绝对路径试试。还有检查下文件最终是否删除了。= = 最后,用@来抑制警告。

0
qii
qii

引用来自“YY-OiCiU”的答案

unlink传递绝对路径试试。还有检查下文件最终是否删除了。= = 最后,用@来抑制警告。

文件没有被删除,用的是绝对路径.
0
YY-OiCiU
YY-OiCiU
貌似你是要删除上传后的文件?
0
qii
qii

引用来自“YY-OiCiU”的答案

引用来自“qii”的答案

引用来自“YY-OiCiU”的答案

unlink传递绝对路径试试。还有检查下文件最终是否删除了。= = 最后,用@来抑制警告。

文件没有被删除,用的是绝对路径.

我没遇过类似的问题,网上有文章提到,如果你已经打开了那个文件的句柄,那么unlink之前需要释放句柄。。。

http://php.net/manual/en/function.unlink.php

I have been working on some little tryout where a backup file was created before modifying the main textfile. Then when an error is thrown, the main file will be deleted (unlinked) and the backup file is returned instead.

Though, I have been breaking my head for about an hour on why I couldn't get my persmissions right to unlink the main file.

Finally I knew what was wrong: because I was working on the file and hadn't yet closed the file, it was still in use and ofcourse couldn't be deleted :)

So I thought of mentoining this here, to avoid others of making the same mistake:

<?php
// First close the file
fclose($fp);

// Then unlink :)
unlink($somefile);
?>

谢谢。
返回顶部
顶部