Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,996
    Thanks
    15
    Thanked 233 Times in 233 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    maybe use a javascript onclose or beforeclose or something

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you could try sqlite it doesnt use a database but just a file on the server ( its free)

    http://www.sqlite.org/about.html

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Looking at that it appears to be for c/c++. How does php use that?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,996
    Thanks
    15
    Thanked 233 Times in 233 Posts
    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.

  • #8
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    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

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    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..
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #10
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,055
    Thanks
    10
    Thanked 94 Times in 92 Posts
    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)

  • #11
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts

  • #12
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you tried with the javascript codes?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •