当会话将在php中销毁时销毁文件 [英] Destroy files when session will destroy in php

查看:62
本文介绍了当会话将在php中销毁时销毁文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在会话将销毁时从文件夹中删除文件.当用户进入网站时,他可以上传文件(图像或文本文件)等,而无需登录该网站.文件将存储到我的项目的文件夹中.现在,我需要执行以下操作:如果用户未登录而从浏览器中退出,则需要删除他上载到项目文件夹中的所有文件.该怎么做?

is it possible to remove files from the folder when session will destroy. am doing that when a user come into the site and he can upload files(images, or textfiles), etc.. with out login into the site. and the files 'll store into my project's folder. now i need to do if the user quits from browser with out login i need to delete all the files what he upload in to project folder. how to do this ?

谢谢.

推荐答案

您可以通过实现自己的会话处理程序来实现.这样,您可以为各种事件定义一个回调,包括会话的破坏.有关更多信息,请参见此链接:

You can do this by implementing your own session handler. This way, you can define a callback for various events, including the destruction of a session. See this link for more information:

http://www.php.net/manual/zh-CN/function.session-set-save-handler.php

更新:该解决方案的问题在于,您还需要实现其余的会话处理代码(初始化会话,关闭会话,从存储中读取,写入,进行垃圾收集).但是,上面的链接页面提供了完整的示例,您可以向其中添加功能.

Update: The problem with that solution is that you need to implement the rest of the session handling code as well (initialize the session, close the session, read from storage, write, garbage collect). However, the linked page above gives a full example that you can add your functionality to.

这篇关于当会话将在php中销毁时销毁文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆