Find out if a session with a particular id has expired

后端 未结 3 393
独厮守ぢ
独厮守ぢ 2021-01-28 09:13

I am creating an upload feature that stores a user uploaded file on the server with the user\'s session-id as its name. Now, I want to keep this file on the server only till tha

3条回答
  •  无人共我
    2021-01-28 09:33

    I'm trying to do the exact same thing. One solution would be to define a custom garbage collector function with session_set_save_handler(). In this custom function you would delete the uploaded files associated with the session and then delete the session from disk. The only problem I see it's that you will have to define the rest of the session handlers as well:

    bool session_set_save_handler ( callback $open, 
                                    callback $close, 
                                    callback $read, 
                                    callback $write, 
                                    callback $destroy, 
                                    callback $gc )
    

    This is easy if you don't rely on PHP to handle sessions. Is there a way to call the default handler functions of PHP from a custom handler function?

提交回复
热议问题