Click to See Complete Forum and Search --> : adding an upload field to my form


Baby Jai
03-19-2008, 05:55 AM
i sthere a way to add an upload section on my form and have it upload to a folder on the site and from there when they submit it it uploads, shows a lil progress bar, and boom when i get the email, it has a link to the picture or embedds it? I alread yknow the coding for the form and having it send via email, its just adding the photos to it which confuses me.

hastx
03-19-2008, 08:44 AM
uploading is the easy part. you might check the sticky post on this forum for uploading images. There are also many other discussions here for adding uploads.

The progress bar requires more code and if that is what you want you might look into some pre-built flash or java uploaders. there is also one here (http://www.raditha.com/php/progress.php) that you can look at.

Once you get the upload working then you can look at placing a link to it in the email.

Baby Jai
03-20-2008, 09:12 AM
well based on this code, how would i set the different file extensions allowed

<?php
global $DB;
require('conf.php');
$DB = connect();
//Properly prepares data for database
function escape_data ($data) {
if (ini_get('magic_quotes_gpc')){
$data = stripslashes($data);
}
return mysql_escape_string($data);
}
//End Function
If($_GET['m'] == 1){
If(isset($_POST['submit'])){
IF($_POST['Email_Address'] == $_POST['Email_Address_Confirm']){
IF (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['Email_Address'])))) {
$email = escape_data($_POST['Email_Address']);
} ELSE {
$email = "N/A";
}
}ELSE{
$email .="Emails didn't match, here is the first one they entered: ".escape_data($_POST['Email_Address']);

}
IF(is_uploaded_file($_FILES['Upload_File']['tmp_name'])) {
$zip=$_FILES['Upload_File']['name'];
}ELSE{
$message = "<li>Please choose a picture file to upload and make sure it isn't over 5MB</li>";
$zip= "N/A";
}
IF(isset($_POST['Folder_Name'])){
$folder = escape_data($_POST['Folder_Name']);
}ELSE{
$folder = "N/A";
}
IF (!isset($message)){
IF($zip != "N/A"){
$extension = explode('.', $zip);
$time = time();
$time = substr($time,0,-5);
$filename = $extension[0].'-'.$time.'.'.$extension[1];
IF(!move_uploaded_file($_FILES['Upload_File']['tmp_name'],"whatever/{$filename}")){
$message .="<li>Sorry, your picture file couldn't be uploaded</li>";
}
}
If(isset($filename)){
$filename = "http://www.whatever.com/whatever/".$filename;
}ELSE{
$filename = "NONE PROVIDED";
}

IF (!isset($message)){
$emessage="You have an application from {$email} to upload {$filename} to folder ($folder)";


@mail("whatever@babyjai.com", "Application for whatever", $emessage, "From: {$email} \r\n");
$thanks = "<b>Thanks for submiting your picture to BJO! Please be sure to check your email for a response from your application.</b>";
$_POST = array();
}
}
}}
?>