how to temporary safe image and later save permanently

Discussion in 'PHP' started by adsegzy, Oct 6, 2010.

  1. #1
    Hello friends,

    I have a form where people upload images and other information. Once the person finished filling the form a PREVIEW PAGE will come to show the information filled in the form. The problem is that i don't know how to temporarily save the uploaded image and use session to carry it to the PREVIEW PAGE in order to preview it with other information and also how to same it permanently if the person clicks submit or delete it if the person clicks EDIT.

    I need your assistance.

    Regards,
    adsegzy
     
    adsegzy, Oct 6, 2010 IP
  2. veroxii

    veroxii Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have 2 upload directories. One for previews and one for the final saved ones. So when they upload the file you save it to the previews directory and store the filename in a session variable.

    Then on the preview page do whatever you have to do, and in the script that handles the submit and delete buttons you then either delete the file with the php delete() command or move it to the permanent directory. You can move files around in php with rename().
     
    veroxii, Oct 6, 2010 IP
  3. veroxii

    veroxii Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Also, forgot to mention... you can have some sort of cronjob or something similar to clean up the previews directory occasionally (eg. delete all files older than an hour).
     
    veroxii, Oct 6, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    By default all HTTP uploads are saved to the temporary directory (/tmp) so you can use that and if you wish to save it....use move_uploaded_file()

    You can set the tmp_name as a $_SESSION, so it can be retrieved on other pages.
     
    danx10, Oct 7, 2010 IP