Photo upload form help
Posted: Mon Feb 16, 2009 10:12 am
Hi there,
I'm currently helping maintain a website, and I've been asked to develop an upload form for a competition...
The general idea is pretty basic...the user uploads an image, along with their name and info. The image is stoed on the server, and the other info is sent to an email address.
The way I'm trying to make it, is so that the user uploads their image to the server (I can do this perfectly fine) and is taken to another page, which immediately displays their image, and has a form for their email address, name, number, etc
This form will be emailed to a specific email address (along with the file name)
I know this may be a fairly roundabout way of doing things, but I'm at a loss with the whole MySQL database idea.
Has anyone got any ideas/tips/help/feedback on what I'm doing (well, *trying* to do...)
Any help ill be greatly appreciated!!
Thanks,
Colin
FYI, this is the code I currently have for the 2nd form page (the page shown after the file is uploaded)
Everything works fine and it gets to this page, but I can't quite get my head around the IMG SRC on the 4th from bottom line...I have a semi-idea that its to do with the <? being closed, but I'm not at a high enough level right now to be sure/fix it (I can happily admit I'm still learning)
<?php
if ((($_FILES["file"] ["type"] == "image/pjpeg")
|| ($_FILES["file"] ["type"] == "image/jpeg"))
&& ($_FILES["file"] ["size"] < 1048576))
{
if ($_FILES["file"] ["error"] > 0)
{
echo "Return Code: " . $_FILES["file"] ["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"] ["name"] . "<br />";
echo "Type: " . $_FILES["file"] ["type"] . "<br />";
echo "Size: " . ($_FILES["file"] ["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"] ["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"] ["name"] ))
{
echo $_FILES["file"] ["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"] ["tmp_name"] ,
"upload/" . $_FILES["file"] ["name"] );
echo "Stored in: " . "upload/" . $_FILES["file"] ["name"] ;
}
}
}
else
{
echo "Invalid file";
}
?>
<img src="upload/ . $_FILES["file"] ["name"] . ">
<p> </p>
<p><strong>Fill out the form below to validate your details!</strong></p>
<div id="content">
I'm currently helping maintain a website, and I've been asked to develop an upload form for a competition...
The general idea is pretty basic...the user uploads an image, along with their name and info. The image is stoed on the server, and the other info is sent to an email address.
The way I'm trying to make it, is so that the user uploads their image to the server (I can do this perfectly fine) and is taken to another page, which immediately displays their image, and has a form for their email address, name, number, etc
This form will be emailed to a specific email address (along with the file name)
I know this may be a fairly roundabout way of doing things, but I'm at a loss with the whole MySQL database idea.
Has anyone got any ideas/tips/help/feedback on what I'm doing (well, *trying* to do...)
Any help ill be greatly appreciated!!
Thanks,
Colin
FYI, this is the code I currently have for the 2nd form page (the page shown after the file is uploaded)
Everything works fine and it gets to this page, but I can't quite get my head around the IMG SRC on the 4th from bottom line...I have a semi-idea that its to do with the <? being closed, but I'm not at a high enough level right now to be sure/fix it (I can happily admit I'm still learning)
<?php
if ((($_FILES["file"] ["type"] == "image/pjpeg")
|| ($_FILES["file"] ["type"] == "image/jpeg"))
&& ($_FILES["file"] ["size"] < 1048576))
{
if ($_FILES["file"] ["error"] > 0)
{
echo "Return Code: " . $_FILES["file"] ["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"] ["name"] . "<br />";
echo "Type: " . $_FILES["file"] ["type"] . "<br />";
echo "Size: " . ($_FILES["file"] ["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"] ["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"] ["name"] ))
{
echo $_FILES["file"] ["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"] ["tmp_name"] ,
"upload/" . $_FILES["file"] ["name"] );
echo "Stored in: " . "upload/" . $_FILES["file"] ["name"] ;
}
}
}
else
{
echo "Invalid file";
}
?>
<img src="upload/ . $_FILES["file"] ["name"] . ">
<p> </p>
<p><strong>Fill out the form below to validate your details!</strong></p>
<div id="content">