Aristotl3
02-21-2007, 05:44 PM
Hello,
I would like to create a web form that is either HTML or PHP. I need to have several text boxes and then an area where people can attach an image from their hard drive. When they hit the submit button, the information (and image) will need to be sent to an email address.
I have looked for scripts that do this, but have not had any luck.
Can anyone help me?
Thanks.
Host81
02-21-2007, 05:50 PM
There is a PHP example somewhere...
it's got a lot to do with the HTML form in the first place, you've got to get the type right.
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
<?
/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
$target_path = "images/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
Should do the trick.
Aristotl3
02-21-2007, 06:08 PM
Not sure I understand.. are those two different files? One being the HTML form and the other being a php code file? Also, it seems like this will store the images to a directory..
I am wanting to have mulitple text fields and an image upload field. And I am wanting to have all of this info be emailed (instead of storing it in a directory)
horizon
02-21-2007, 08:36 PM
I'd at least change that line:
// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
for:
// This is how we will get the temporary file...
if (isset($_FILES['uploadedfile']['tmp_name']) && is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {
$_FILES['uploadedfile']['tmp_name'];
} // End of if statement.
And since you're showing your own upload status message, I'd change:
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
for:
if (@move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
;)
Jatinder
02-22-2007, 05:47 AM
horizon
I don't think you need to use the is_uploaded_file function since the move_uploaded_file itself checks whether the file specified is a valid upload file. At least thats what the PHP manual says.
I use the following for error checking:
if($_FILES['image']['error'] == 0 || $_FILES['image']['size'] > 0) {
//Valid upload
}
else {
//Error while uploading
}
azizny
02-22-2007, 12:02 PM
Here is your solution ready:
http://www.free-php-scripts.net/P/Contact_Form
You can actually choose which files to allow, send via email or store on the server.
Peace,
ubersmith_boo
02-22-2007, 03:33 PM
The only bit I can add to help is to make sure that you do not forget the enctype="multipart/form-data" in the form tag. I've spent hours and hours trying to figure out why a file upload would not work, literally pulling my hair out until I realized that I had forgotten the most basic step.
It's the kind of thing I'd consider having tatooed somewhere just to make sure I never forget it ever again.
ubersmith_boo
02-22-2007, 03:35 PM
double posted by mistake.
Aristotl3
02-23-2007, 04:51 PM
azizny:
How can I customize that script? I would like to add a few other text fields.. I assume that I would change the config.php file - but I am not sure what to change..