spacepoet Posted February 23, 2011 Share Posted February 23, 2011 Hello: I would like to know how I can add the option to upload JPGs and/or PDFs to the form I have. I believe I will need to allow 3 uploads once the whole form is done, but I'm trying to keep it small as I learn this. Currently, the form saves the data to the database, and emails the results to a contact. This is fine - just what I need to do most of the time. However, what I'm interesting in doing for this form is to allow the end user to upload/attached JPGs and/or PDFs and save then to the database (and I believe I will need to save the files in a folder on the server, I have one called "EmailedImages"), and then email the results to the contact, including links that will allow the contact to click and download the attached JPGs and/or PDFs. I haven't done this before, so can someone point me in the direction of how to do this, or should an example with the code I use: <?php $error = NULL; $myDate = NULL; $FullName = NULL; $Email = NULL; if(isset($_POST['submit'])) { $myDate = $_POST['myDate']; $FullName = $_POST['FullName']; $Email = $_POST['Email']; if(empty($FullName)) { $error .= '-- Enter your Full Name. <br />'; } if(empty($Email)) { $error .= '-- Enter your Email. <br />'; } if($error == NULL) { $sql = sprintf("INSERT INTO myContactData(myDate,FullName,Email) VALUES ('%s','%s','%s')", mysql_real_escape_string($myDate), mysql_real_escape_string($FullName), mysql_real_escape_string($Email); if(mysql_query($sql)) { $error .= 'Thank you for contacting us.'; mail( "[email protected]", "Contact Request", "Date Sent: $myDate\n Full Name: $FullName\n Email: $Email\n", "From: $Email" ); } else { $error .= 'There was an error in our Database, please Try again!'; } } } echo '<span class="textError">' . $error . '</span>'; ?> <form name="myform" action="" method="post"> <input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" /> Full Name: <input type="text" name="FullName" size="45" maxlength="50" value="<?php echo $FullName; ?>" /> Email: <input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" /> <input type="submit" name="submit" value="Submit" /> </form> Any help would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/228562-never-did-this-before-so-seeking-form-uploading-images-help/ Share on other sites More sharing options...
optikalefx Posted February 23, 2011 Share Posted February 23, 2011 best explanation of files here http://www.tizag.com/phpT/fileupload.php Link to comment https://forums.phpfreaks.com/topic/228562-never-did-this-before-so-seeking-form-uploading-images-help/#findComment-1178507 Share on other sites More sharing options...
spacepoet Posted February 23, 2011 Author Share Posted February 23, 2011 Hi: Thanks. Should I be able to integrate the code on that link into my existing form code I posted? I would think I need to add a "filename" type of field as well to store that in the database. Link to comment https://forums.phpfreaks.com/topic/228562-never-did-this-before-so-seeking-form-uploading-images-help/#findComment-1178513 Share on other sites More sharing options...
optikalefx Posted February 23, 2011 Share Posted February 23, 2011 yep just add a field to your database. then add a <input type="file" name="database_field_name"/> and then you need to just add the new filename and location (once its uploaded and moved - follow the tutorial) to your database table. Link to comment https://forums.phpfreaks.com/topic/228562-never-did-this-before-so-seeking-form-uploading-images-help/#findComment-1178818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.