Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-10-2012, 06:05 PM   PM User | #1
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,228
Thanks: 11
Thanked 156 Times in 156 Posts
DrDOS is infamous around these parts
How can I delete files at end of $_SESSION?

I'm putting together a site, entirely my own project, where you can process images in all kinds of ways, crop and resize them, add text in any variety of fonts, colors and sizes, add insets of several kinds, make flyers and posters, etc,etc, etc. All of that works and wasn't that hard to write.

But here's my problem, I've set it up so that as soon as someone enters the site they are assigned a name for their working folder and as soon as they upload a picture the folder is made, inside a folder named Pool, then the images are placed inside their folder. But I don't want to store images, I want the folder and its contents to be automatically deleted shortly after their browser is closed and their session ends. How do I do this, I don't know, haven't got a clue, about how to call a function at the end of their session or after it has closed. Because nothing is stored and the site is intended to be free ( except maybe for advanced users ) I see no need for a database.
DrDOS is offline   Reply With Quote
Old 07-10-2012, 06:13 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
PHP does not natively support what you want to do.

The only way to do that, is have your users click a link like logout / finish or to run an automated process.

For the latter option you could in your pages use an ajax request to poll a script every 5 seconds. That script then records the time/date access somewhere - either in the session (not a wise idea), file or DB. On the webserver, have a cron job that runs every 5 minutes and wipes out all files that haven't been used for 5 minutes or more.

The reason I say using sessions to record the time is not a good idea is quite a simple one. Your cron script would need to be able to access all the session files for visitors to your site. While thats not particularly difficult on a windows platform, on a shared host under linux it may be very difficult.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 07-10-2012, 06:20 PM   PM User | #3
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
Arcticwarrio is on a distinguished road
maybe use a javascript onclose or beforeclose or something
Arcticwarrio is offline   Reply With Quote
Old 07-10-2012, 06:40 PM   PM User | #4
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
I know there is an beforeunload (I think thats the right one), but its not a safe thing to use as javascript can be disabled, and you'd just be in a mess.

Javascript should NEVER be used as a safe answer.
Keleth is offline   Reply With Quote
Old 07-10-2012, 08:00 PM   PM User | #5
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
Arcticwarrio is on a distinguished road
you could try sqlite it doesnt use a database but just a file on the server ( its free)

http://www.sqlite.org/about.html
Arcticwarrio is offline   Reply With Quote
Old 07-10-2012, 08:22 PM   PM User | #6
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Looking at that it appears to be for c/c++. How does php use that?
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 07-10-2012, 08:55 PM   PM User | #7
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,228
Thanks: 11
Thanked 156 Times in 156 Posts
DrDOS is infamous around these parts
Thank you all very much for your replies.

I now know that php doesn't natively have such a function. I plan on having more than one way of doing it, such as a weekly cleanup of all files and folders in Pool. I already have it set so they can delete their own files. People have to use javascript on the site, so I can set it so that if they don't have javascript enabled they can't make a folder or upload. I could maybe put a 'cookie' in their folder with just the unix time when they quit on the cookie, and that can be checked regularly. Anyway, I have some ideas now.
DrDOS is offline   Reply With Quote
Old 07-10-2012, 11:05 PM   PM User | #8
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
Arcticwarrio is on a distinguished road
im on my mobile thats the wrong ling lol, i cant remember what its called but the a version of mysql that stores in files instead of a database
Arcticwarrio is offline   Reply With Quote
Old 07-11-2012, 12:58 AM   PM User | #9
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Arcticwarrio View Post
im on my mobile thats the wrong ling lol, i cant remember what its called but the a version of mysql that stores in files instead of a database
Erm.. MySQL DOES store in files. Thats how all databases work - they record data into files and then scan through them to find / change data.

What you were thinking of I've no idea, but I've yet to see a version of mysql that writes data on photons..
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 07-11-2012, 07:22 AM   PM User | #10
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,942
Thanks: 7
Thanked 82 Times in 81 Posts
firepages will become famous soon enough
SQlite was bundled with PHP from 5.0 but they are dropping it back into PECL from 5.4 for reasons I do not know (mad cos with a built in webserver 5.4 would be complete script/server/db all rolled into one... anyways)

I think what Arcticwarrio meant is that with SQLite you could but the database file anywhere you wanted ona per-database/usage basis as opposed to MySQL where you can't change the database path unless you are root.
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 07-11-2012, 08:54 AM   PM User | #11
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
Arcticwarrio is on a distinguished road
http://uk.php.net/manual/en/book.sqlite.php

yeah this one
Arcticwarrio is offline   Reply With Quote
Old 07-11-2012, 10:48 AM   PM User | #12
Roselienjessie
New to the CF scene

 
Join Date: Jul 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Roselienjessie is an unknown quantity at this point
Have you tried with the javascript codes?
Roselienjessie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 PM.


Advertisement
Log in to turn off these ads.