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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Passing Images Thorugh Multiple pages

    Ok heres my problem,
    I have an application form that users fill out online. part of this form deals with them having to upload images.
    my problem is that I have 4 different pages the user goes through in the application process.

    The users upload his picture on the first page,
    What I want is for the pictures the user has uploaded in the form to only stay saved once they finish the application
    I though a $_SESSION would keep the pictures safe until they were uploaded them on the last page, but i was wrong.

    So what do I need to do to tell PHP to keep the images uploaded temporarily through multiple pages and not upload them into a permanent folder until the application process is finished?

    basically all im looking for is something equivalent to a $_SESSION that can hold the actual image.

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could save them to a temp folder and only move them somewhere to keep at the end of the process.

    An image could be way too big to keep in session data, it would be much more effecient to store it in a temp folder and pass the filename around in a session variable.

  • #3
    New Coder
    Join Date
    Nov 2007
    Location
    Kent, United Kingdom
    Posts
    67
    Thanks
    6
    Thanked 2 Times in 2 Posts
    then on the last page you could have the script delete the image =]
    unset()

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    unset() does variables. I think you mean unlink();

  • #5
    New Coder
    Join Date
    Nov 2007
    Location
    Kent, United Kingdom
    Posts
    67
    Thanks
    6
    Thanked 2 Times in 2 Posts
    lol, yes i did mean unlink :P, sorry i wrote that post at like 2am so sorry for my errors :P

  • #6
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    oh that makes perfect sense!
    thank you.
    but i have one question.
    How would I go about making a temp folder?

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Put it at a level above your html directory (this way it can't be linked by the outside world). Just make a new folder like you would any other folder, call it temp.

    Code:
    root
        public_ftp
        public_html
            index.php // site here
        temp_uploads // uploads go here
    something like that

  • #8
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ok i get that. but i mean how does the temp folder automatically delete the images if the application wasnt fully processed?

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    It doesn't; you delete them with a cron job or at the start of the script using filemtime() or similar to make sure the file is old enough to not still be in use.

  • #10
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ok thank you.
    except i dont think my setup does not support cron jobs.
    how could i make a script that checks the folder and auto delete the files once a day just using php alone?
    or is the a possible fix that emulates a cron job that can just delete my temp folder systematically?
    Last edited by elementis0; 12-27-2007 at 02:50 AM.

  • #11
    New Coder
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have also learned something new here

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by elementis0 View Post
    how could i make a script that checks the folder and auto delete the files once a day just using php alone?
    You would need to store the last time it was run in a database or text file, check for it on each pageload, and if it was last run more than a day ago execute the delete script. This is just an example of how you could delete the files; is not tested, but it should get you started:
    PHP Code:
    $temp_folder './temp/'// with trailing slash
    $d dir($temp_folder);
    while (
    false !== ($entry $d->read()))
    {
        if(
    $entry[0] != '.' && !is_dir($temp_folder $entry) && filemtime($temp_folder $entry) < (time() - (60 60 24))) // ignore directory pointers, directories, and files newer than a day old
        
    {
            
    unlink($tempfolder $entry);
        }
    }
    $d->close(); 

  • #13
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    well i understand how to delete the files and all.
    but what I really dont get is how to make the script auto-execute every day without using cron.

    i think i may need a more thorough explanation of how to make it so it just autodeletes the files in the foler by checking the database or textfile.

    I would just really like to thank you for all the help you have given me so far.

  • #14
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    PHP Code:
    $filename 'last.txt';
    $last file_exists($filename) ? file_get_contents($filename) : 0;
    $last intval($last);

    if(empty(
    $last) || $last time() - (60 60 24))
    {
        
    // delete files
        
    $return file_put_contents($filenametime());

    You can add more error checking if you want.

  • Users who have thanked Inigoesdr for this post:

    elementis0 (12-28-2007)

  • #15
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thank you so much!
    one last thing and then ill probably be sastisfied lol.

    how do i make this script run by itself without have to actually manually execute it?
    is that possible without crontabs?
    Last edited by elementis0; 12-28-2007 at 08:16 AM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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