Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submit a form and upload a picture

Status
Not open for further replies.

dldl

Programmer
May 3, 2010
40
0
0
NZ
Hi;
I am writing a submit form to let people to submit their information and upload a picture.

The problem for me is after i upload a picture, how i can let it display on the submit form,and also keep the values i just type for the fname and the age ?

Could anyone give me some idea, please. Thanks

submitform.php

<html>
<body>

<form action="process.php" method="post">
Name: <input type="text" name="fname" /><br>
Age: <input type="text" name="age" /><br>
a picture will display here after upload<br>
<a href="addpic.php">click here to add picture</a>
<input type="submit" name="submit" value="submit">
</form>

</body>
</html>


addpic.php

<form action="uploadpic.php method="post"
enctype="multipart/form-data">
<div>
<label for="file">picture:</label>
<input type="file" name="pic" id="pic">
<br>
<input type="submit" name="submit" value="submit">
</div>
</form>


uploadpic.php

<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "the file i uploaded is : " . $_FILES["file"]["name"] . "<br />";

}
?>
 
the values are in the POST array. so just echo the values back out in the value attribute of the relevant <input> tags.

you have not provided the logic flow of your application however, so more precise assistance is difficult to provide.
 
To display the picture you would need to take its current path and construct an image tag (<img src='...'>) around it to display it, but as jpadie mentions this is just the basic answer, without knowing more about your application its difficult to provide more assistance.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
sorry, my plan is i will write a form to let people submit
their information and upload an image.

My question is


first I let user to fill some information, then upload an image, after upload an image, the image will display
in the form, and then i can submit the information the user provided and the image. This is all i want to do.

Can i do it in one form or i have to do it in two form (one for submit information and one for upload image) and how to do it.
i never submit information and upload image together before,
so i have not idea about that.
 
Basically you could have the entire thing in a single form, except you won't see the image in the form until after you submit the form.

What happens is the image is uploaded at the same time the form is submitted.

You could if you wanted to, re-display the filled in form with the uploaded picture as a sort of confirmation if you will.
Or just display the image, and the form's data in a confirmation page.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
or have the picture upload done by a flash control or a page within an iframe.
 
Thanks guys. i am going to try it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top