如何删除已打开的文件?
我正在使用 fopen 并将其保存到我的共享主机 /tmp 目录中。我关闭它,但 tmp 文件没有删除。我怎样才能删除这个?
PHP5,顺便说一句。
I'm using fopen and it's saving to my shared hosts /tmp directory. I fclose it, but the tmp file doesn't delete. How can I delete this?
PHP5, btw.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 unlink()
fclose 只是关闭流,不会执行任何操作文件本身。
Use unlink()
fclose just closes the stream, doesn't do anything to the file itself.
如果文件可通过
$_FILES
访问(HTTP 文件上传通常是这种情况),您可以使用unlink($_FILES['userfile']['tmp_name']) 删除临时文件。请参阅:POST 方法上传
If the file is accessible via
$_FILES
(which is usually the case for HTTP file uploads), you can useunlink($_FILES['userfile']['tmp_name'])
to delete the temporary file. See: POST method uploads