SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing image upload info across two php files

    hi, i have a form that allows user to upload up to 6 jpgs...but they can upload only 1 or 2 or watever they want...but at least 1.
    once they press submit...the info along with the pictures are sent over to a review page that simply redisplays the data, copies files to the server and redisplays them (resized using GD), and then asks person if they want to modify their entry or process it.

    if modify is clicked, the user is sent to a form page that redisplays their content (using hidden forms in the review page that resend the info)...if process, inserts all info into a database.

    now, the form is an HTML page, the review is a PHP and the Processing (whether modify or submit) is another PHP file. The images info are sent to the first php with $_FILE['imagefile']['name'][$idx] (since its an array of imagefile() used in the forms).

    I need to send the image info to the next PHP file...how do I do that? I can't do it using the Hidden Form method.

    Any thoughts? PLEASE HELP ME!!!

  2. #2
    SitePoint Zealot alexisb's Avatar
    Join Date
    Aug 2003
    Location
    Lima, Peru
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I have a similar need.

    In my case the visitor is filling a form with some text data (name, address, etc), and he also can upload his picture.

    I am validating the form to see is the visitor completed names, entered a valid phone number and such. If there is some data not entered the form is shown again letting him know what he missed and maintains the data in the fields already filled.

    My problem is that the upload image info is not maintained, the visitor has to reselect the file to be uploaded.

    Is there any way to "remember" the upload information? We can use this with text fields:

    Code:
    <input value="<?php echo $lastValue ;?>" type="text">
    Can I do something similar with image fields?

    Regards!

  3. #3
    SitePoint Zealot sanka69's Avatar
    Join Date
    Apr 2003
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    If I understand your problem correctly, you do not need to re-promt the user for the image, or cache the file in a text field.

    How I've approach this before is when the user initially uploads their image, that file is copied to a "sandbox" directory. I also generate a thumbnail, and store this image in the directory too.

    The filename is then stored in a session, and I reference that file throughout the validation steps.

    Should the user want to re-upload the image, the old files are removed, and the new files take their place.

    Finally, once the validation steps are complete, I take the file from the sandbox, and move it into the correct location.

    Hope this helps,
    Richard

  4. #4
    SitePoint Zealot alexisb's Avatar
    Join Date
    Aug 2003
    Location
    Lima, Peru
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Richard, thank for your suggestion, here is some more information about my situation:

    This is the form tag I'm using:

    Code:
    <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>">
    You can see the form is calling itself, depending on some validations some methods are called. I'm using OO PHP but the same could be done with just functions.

    One of the first methods called is validate(), which check if the fields were filled correctly.

    If I understand you correctly I should check if the image was correctly uploaded at this step and, if so, I could put the image in the sandbox, forget about it and continue with the validation, if needed asking the user to complete the missing fields.

    Later when all needed fields are completed and before putting the info into the database (which is the final step in my process) I would check if there is an associated image for this record in the sandbox and include it.

    Have I understood correctly?

    If you could provide any other detail about the process it would be great.

    Thanks!

  5. #5
    SitePoint Zealot sanka69's Avatar
    Join Date
    Apr 2003
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    You've understood me exactly. Any other steps in the process.. hmm. Not really much else to comment on since it's all there.

    When I've done this, I've used a small wrapper class that generates the thumbnail. and I also have a class which encapsulate handling form variables (providing persistence by ultimately, storing $_POST in the Session array). A DAO class to wrap the database access.

    On the form I'd have a hidden field that would be a flag to indicate if a file was uploaded. When checking the $_POST data on submission, anything in $_FILES would take precedent over the flag, and a new image uploaded and put in the sandbox. If I had to return to the input form for the user, I'd display the new thumbnail on the form, set the flag field, but give the user another chance to specify another image if they wanted.

    When validate() was okay, I'd then save to the database, and move the file outside of the sandbox to it's correct location.

    If it helps, my sandbox also deletes any files that are older than 20 minutes by a basic cron script that runs every few hours.

    hth,
    Richard

  6. #6
    SitePoint Zealot alexisb's Avatar
    Join Date
    Aug 2003
    Location
    Lima, Peru
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent method Richard, thank you very much for sharing It is very clear now.

    I'll implement it and will let your know.

    Regards!


Bookmarks

Posting Permissions

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