atomicrabbit Posted December 10, 2009 Share Posted December 10, 2009 Ok I need to be able to create a temporary file in the same way that php creates a temporary file when uploading files. When a file is uploaded, php will store a temporary file at /home/username/tmp (and can be referenced by $_FILES["upload_name"]["tmp_name"]). Then via php you can use move_uploaded_files to move the temporary files to another location on the server. If the user does not move the file from the tmp directory and the php script finishes or if the move_uploaded_files function fails, php will automatically delete the temporary file. Can this sort of functionality be re-created. I'm looked into tempnam and tmpfile, but neither will accomplish the automatic deleting. Or can someone offer an alternative? Quote Link to comment https://forums.phpfreaks.com/topic/184669-create-temporary-file-that-will-be-automatically-deleted/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 10, 2009 Share Posted December 10, 2009 Why not store the file in a session variable? It will be automatically deleted when the session ends. Quote Link to comment https://forums.phpfreaks.com/topic/184669-create-temporary-file-that-will-be-automatically-deleted/#findComment-974961 Share on other sites More sharing options...
atomicrabbit Posted December 10, 2009 Author Share Posted December 10, 2009 is that efficient? I read that it could be a problem depending on the size of the file. It could slow down the loading of the page. Quote Link to comment https://forums.phpfreaks.com/topic/184669-create-temporary-file-that-will-be-automatically-deleted/#findComment-974990 Share on other sites More sharing options...
atomicrabbit Posted December 11, 2009 Author Share Posted December 11, 2009 when you say "when the session ends" do I have to close the session? Quote Link to comment https://forums.phpfreaks.com/topic/184669-create-temporary-file-that-will-be-automatically-deleted/#findComment-975132 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2009 Share Posted December 11, 2009 By default, the session id cookie has a zero session.cookie_lifetime setting and the cookie expires when all open browser windows/tabs are closed. session garbage collection will then automatically remove the session data files that are older then the session.gc_maxlifetime setting. Quote Link to comment https://forums.phpfreaks.com/topic/184669-create-temporary-file-that-will-be-automatically-deleted/#findComment-975427 Share on other sites More sharing options...
atomicrabbit Posted December 11, 2009 Author Share Posted December 11, 2009 great that's exactly what I needed to know! I guess I can also unset the session to clear all the variables if the script completes successfully as well. Thanks for the insight, PFMaBiSmAd! Quote Link to comment https://forums.phpfreaks.com/topic/184669-create-temporary-file-that-will-be-automatically-deleted/#findComment-975532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.