...

View Full Version : problem passing uploaded file from page 1 to page 2 in form



icesa
05-07-2004, 12:44 PM
Hi, I'll start by saying that I'm a total beginner with php so I apologize in advance if I sound stupid.

I made a 3-page form:

Page 1 has several fields including one allowing users to upload an image file.
Page 2 has fields requiring additional information
Page 3 has fields requiring yet more information and, as the final page, sends it all to me by email.

Now, in the email I get all information from page 1 (that was passed on to page 2, then to page 3), from page 2 (passed on to page 3) and, of course from page3. I get it all except the uploaded file attachment from page 1.

I'd like to know how to "capture" the file uploaded in page 1 and pass it on to page 2, then page 3 so it is included in the email sent to me as an attachment.

Can anyone help me? Thank you. David

raf
05-07-2004, 03:49 PM
Welcome here !

why can't you drag along the fileadress like you do with the rest of your cata. i don't see the problem.

icesa
05-07-2004, 05:03 PM
Hi,
Thank you for your reply.

Here is part of the code I use to pass values from page to page:

Page 1:
<body>
<form name="form" action="order-windows.php" method="post" enctype="multipart/form-data">
<input type="text" name="ni_mod">
<input type="text" name="ni_dim">
<input type="file" name="upfile">
<input type="submit" name="submitButtonName" value="Submit">
</form>
</body>

Page 2: (name of page: order-windows.php)
<body>
<form name="form" action="order-payment.php" method="post" enctype="multipart/form-data">
<? php
$ni_mod =htmlentities($_POST['ni_mod']);
$ni_dim =htmlentities($_POST['ni_dim']);
$upfile= htmlentities($_FILES['upfile']);
?>
<input type="hidden" name="ni_mod" value="<?php echo$ni_mod; ?>">
<input type="hidden" name="ni_dim" value="<?php echo$ni_dim; ?>">
<input type="hidden" name="upfile" value="<?php echo$upfile; ?>">
<input type="text" name="id_type">
<input type="text" name="id_style">
<input type="submit" name="submitButtonName" value="Submit">
</form>
</body>

Page 3: (name of page: order-payment.php)

<body>
<form>
<form name="form" action="orderstandard.php" method="post" enctype="multipart/form-data">
<? php
$ni_mod =htmlentities($_POST['ni_mod']);
$ni_dim =htmlentities($_POST['ni_dim']);
$upfile= htmlentities($_FILES['upfile']);
$id_type =htmlentities($_POST['id_type']);
$id_style =htmlentities($_POST['id_style']);
?>
<input type="hidden" name="ni_mod" value="<?php echo$ni_mod; ?>">
<input type="hidden" name="ni_dim" value="<?php echo$ni_dim; ?>">
<input type="hidden" name="upfile" value="<?php echo$upfile; ?>">
<input type="hidden" name="id_type" value="<?php echo$id_type; ?>">
<input type="hidden" name="id_style" value="<?php echo$id_style; ?>">
<input type="text" name="cc">
<input type="text" name="wire">
<input type="submit" name="submitButtonName" value="Submit">
</form>
</body>

That's what I have. I try to pass along the value for the uploaded file (input type="file" name="upfile") but it doesn't work. When I receive the email, all information appears in the message except upfile's value and the attachment.

I'd like to know what I have to do to:

1. have the selected file uploads when user clicks submit button on page 1,
2. retrieve and forward file to page 3 when user clicks submit button on page 2,
3. retrieve and send file by email as attachement when user clicks submit button on page 3.

Thank you. David

raf
05-07-2004, 07:34 PM
You aren't uploading the file, right?
check out http://www.php.net/features.file-upload on how to move the uploaded file. Then you store the filename or adress of the moved file inside $upfile

then inside page 3, you need to change
$upfile= htmlentities($_FILES['upfile']);
into
$upfile= $_POST['upfile'];
--> it's the post-collection you need + you're not printing the html so why convert it to entitys.

echo$ni_mod;
should also better be
echo $ni_mod;

icesa
05-08-2004, 12:38 AM
Yes, I want whichever file the user has selected with the input file element on the first page to be uploaded when he/she clicks submit to continue on to page 2. In the end, I want this file to be passed along from page 1 to page 3 so that when user clicks submit on page 3, the file gets attached to the email that is sent to me.

As I said, I'm new to php and quite frankly I just don't get it. I've been reading posts on forums and php manual for days and it all sounds like Chinese to me. I don't want to become a coding champion. I just want to somehow be able to add this feature to my form and move on.

Can you show me how it's done? Or is there any user-friendly software I can buy that would achieve this?

Thank you. David

raf
05-08-2004, 12:44 AM
It's very simple.

The file gets uploaded after page one is submitted. You then need to move the uploaded file from the temporarely location to a location to store it until the mail is sent. All the code you need for this is inside the example in the link i posted.
At that stage, you have the fileadress, and you then just pass along the fileadress, just like the other values. The file itself just sits n the directory you moved it to.
When you build the mail, you then attach the file to is using the fileadress.

If your not planning on learning to code this, then download a ready made class that does this all for you. Just google for 'PHP upload mail' or take a look at the usercomments in the link i posted or at www.hotscripts.com or www.phpclasses.org

icesa
05-08-2004, 12:53 AM
Ok, I'm starting to understand the sequence here.
Thank you very much for your help and your patience. David



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum