PHP - Email Php Form - Need To Add Ability To Accept File Uploads
Hi
Have got my form working for all standard bits. Just need to add the functionality for people to upload photos. I copied and modified the form from a site and there is a section that I think is redundant it still works when I comment it out can you clarify for me: Code: [Select] // validation expected data exists /* if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } */ Below is the full code for the form: Code: [Select] <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "asdfasdf@asdfasdf.com"; $email_subject = "adsfasdf asdfasdf Application Form"; function died($error) { // your error code can go here ?> <title>asdfas asdfasd</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onLoad="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfasdf" longdesc="http://www.adsfasdf.com" /><br /> </p> <br /> <p>We are very sorry, but there were error(s) found with the form you submitted.</p> <p>Please fix the following errors:</p> <hr /> <br /> <?php echo $error; ?> <hr /> <br /> <p>Click back to fix your error(s) or you will be taken back to the form automatically in 10 seconds...</p> <h6> </h6> <h6>© asdfasdf 2012</h6> </body> </html> <?php die(); } // validation expected data exists /* if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } */ $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $age = $_POST['age']; $city = $_POST['city']; $state = $_POST['state']; $height_feet = $_POST['height_feet']; $height_inches = $_POST['height_inches']; $error_message = ""; $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'First Name: This is not a valid name.<br /><br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'Last Name: This is not a valid last name.<br /><br />'; } $age_exp = "/^(1[89]|[2-9][0-9])$/"; if(!preg_match($age_exp,$age)) { $error_message .= 'Age: You need to be at least 18+ to apply.<br /><br />'; } $phone_exp = "/^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/"; if(!preg_match($phone_exp,$telephone)) { $error_message .= 'Phone: eg 646 555 1234 or 646-555-1234 or (646) 555 1234<br /><br />'; } $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'Email: Your address is not invalid eg yourname@emaildomain.com<br /><br />'; } if(strlen($comments) < 2) { $error_message .= 'Comments: Please leave a breif message explaining your interest and if you have any previous experience etc.<br /><br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below:\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name:"."\t".clean_string($first_name)."\n"; $email_message .= "Last Name:"."\t".clean_string($last_name)."\n"; $email_message .= "Age:"."\t".clean_string($age)."\n"; $email_message .= "Height:"."\t".clean_string($height_feet).'ft ' . clean_string($height_inches).'in'."\n"; $email_message .= "City:"."\t".clean_string($city)."\n"; $email_message .= "State:"."\t".clean_string($state)."\n"; $email_message .= "Email:"."\t".clean_string($email_from)."\n"; $email_message .= "Telephone:"."\t".clean_string($telephone)."\n"; $email_message .= "Comments:"."\t".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <title>adsfas asdfasdf</title> <style type="text/css"> body { background-color: #000; text-align: center; } body,td,th { color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 24px; } </style> </head> <body link="#FFFFFF" onLoad="setTimeout('history.back()',10000)"> <p><img src="../images/logo.png" width="326" height="144" alt="asdfasdf" longdesc="http://www.asdfasdf.com" /><br /> </p> <p>Thank your for applying to asdf adsf. We will be in touch with you very soon.</p> <p>You will be redirected back to the site in 10 seconds...</p> <h6> </h6> <h6>© adsfdasf 2012</h6> </body> </html> <?php } ?> Here is the html form: Code: [Select] <form id="form2" action="./php/joinus.php" method="post" enctype="multipart/form-data"> <fieldset> <div class="wrapper"> <div class="fleft col"> <label class="first_name"> <span class="text-form">Name:</span> <input name="first_name" type="text" value=""> </label> <label class="age"> <span class="text-form">Age:</span> <input name="age" type="tel" value=""> </label> <label class="city"> <span class="text-form">City:</span> <input name="city" type="text" value=""> </label> <label class="telephone"> <span class="text-form">Phone:</span> <input name="telephone" type="tel" value=""> </label> </div> <div class="fleft col2"> <label class="last_name"> <span class="text-form">Last Name:</span> <input name="last_name" type="text" value=""> </label> <span id="validate_height"> <label><span class="text-form">Height:</span> <select style="width:109px;" name="height_feet"> <option value="" selected="selected">Feet</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> <select style="width:109px;" name="height_inches"> <option value="" selected="selected">Inches</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> </select> </label> </span> <label class="state"> <span class="text-form">State:</span> <select name="state"> <option value="" selected="selected">Select a State</option> <option value="Alabama">Alabama</option> <option value="Alaska">Alaska</option> <option value="Arizona">Arizona</option> <option value="Arkansas">Arkansas</option> <option value="California">California</option> <option value="Colorado">Colorado</option> <option value="Connecticut">Connecticut</option> <option value="Delaware">Delaware</option> <option value="District Of Columbia">District Of Columbia</option> <option value="Florida">Florida</option> <option value="Georgia">Georgia</option> <option value="Hawaii">Hawaii</option> <option value="Idaho">Idaho</option> <option value="Illinois">Illinois</option> <option value="Indiana">Indiana</option> <option value="Iowa">Iowa</option> <option value="Kansas">Kansas</option> <option value="Kentucky">Kentucky</option> <option value="Louisiana">Louisiana</option> <option value="Maine">Maine</option> <option value="Maryland">Maryland</option> <option value="Massachusetts">Massachusetts</option> <option value="Michigan">Michigan</option> <option value="Minnesota">Minnesota</option> <option value="Mississippi">Mississippi</option> <option value="Missouri">Missouri</option> <option value="Montana">Montana</option> <option value="Nebraska">Nebraska</option> <option value="Nevada">Nevada</option> <option value="New Hampshire">New Hampshire</option> <option value="New Jersey">New Jersey</option> <option value="New Mexico">New Mexico</option> <option value="New York">New York</option> <option value="North Carolina">North Carolina</option> <option value="North Dakota">North Dakota</option> <option value="Ohio">Ohio</option> <option value="Oklahoma">Oklahoma</option> <option value="Oregon">Oregon</option> <option value="Pennsylvania">Pennsylvania</option> <option value="Rhode Island">Rhode Island</option> <option value="South Carolina">South Carolina</option> <option value="South Dakota">South Dakota</option> <option value="Tennessee">Tennessee</option> <option value="Texas">Texas</option> <option value="Utah">Utah</option> <option value="Vermont">Vermont</option> <option value="Virginia">Virginia</option> <option value="Washington">Washington</option> <option value="West Virginia">West Virginia</option> <option value="Wisconsin">Wisconsin</option> <option value="Wyoming">Wyoming</option> </select> </label> <label class="email"> <span class="text-form">E-mail:</span> <input name="email" type="text" value=""> </label> </div> </div> <label class="message"> <span class="text-form">Comments:</span> <textarea name="comments"></textarea> </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <label> <span class="text-form2">Attach a photo:</span> <input id="photo" name="file[]" type="file" class="fl" > </label> <div class="but"><a class="link1 link-color2" data-type="submit" onClick="document.getElementById('form2').submit()">Submit</a></div> </fieldset> </form> From what I've been reading you need to tell the php to put it to a temporary file from the submit.. then move it to the file name and then somehow include that file name in the php email back. So maybe a url and its private or htaccess? or does it get included as attachment in the mail? Im not sure if i should be using 'id' or 'name' in the html form etc and how to tie it together. Any help or guides much appreciated. Thanks Wolfsta Similar TutorialsHey everyone. I have a form that is working fine. Basically it will upload files to an email address. The files do arrive at the email address, but the problem is that they show up as 0KB in my inbox. Photos, text docs etc., that I upload via the form are arriving in my email at 0KB for some reason. I know the code is messy, but hopefully someone can figure out why the files are uploading as 0KB. **Please see attached code I want to make the form so only people with a specific email address can sign up to the site. So for example their ending email address was.... @something.apple.biz.com .. but to be accepted into the site, the email HAS to end with apple.biz.com. How could you validate it so it matches something specific like this. Here is my code at the moment which just checks that their is at least one . after the @ for it to be an acceptable email. If anyone could say what else to add to do this would be great if($email != '' && $register){ $emailcheck = explode("@", $email); $sql = "SELECT email FROM member WHERE email='$email'"; $query = mysql_query($sql); $emails = mysql_num_rows($query); if($emails != 0 ){ $alert .= '<p class="alert" style="clear:both;">That email address has already been registered</p>'; $register = false; }elseif(count($emailcheck) != 2){ $alert .= '<p class="alert" style="clear:both;">Please enter a valid email address</p>'; $register = false; }elseif(count($emailcheck) == 2){ $emailchecktwo = explode(".", $emailcheck[1]); if(count($emailchecktwo) < 2){ $alert .= '<p class="alert" style="clear:both;">Please enter a valid email address</p>'; $register = false; } } } Stumped! I have a client who has a form where they upload files to their server: title, two password fields, and the file
They have been unable to upload anything over 10m
Small (under 10mb) files work.
Larger doesn’t
I’ve tracked it down, I think, that the processing page appears to be dropping the form values when the file takes a bit to upload.
I echo’ed the values that are grabbed from the form, and they return empty strings if it takes a while for the file to upload (a large file) - they pass fine if the file is smaller.
I think I've got the php info set correctly, but cannot for the life of me figure out how to adjust the timing out issue, or even where to troubleshoot.
Here's my phpinfo:
Max Requests
Per Child: 750 - Keep Alive: off - Max Per Connection: 100
Timeouts
Connection: 120 - Keep-Alive: 5
Directive
Local Value
Master Value
allow_call_time_pass_reference
Off
Off
allow_url_fopen
On
On
allow_url_include
Off
Off
always_populate_raw_post_data
Off
Off
arg_separator.input
&
&
arg_separator.output
&
&
asp_tags
Off
Off
auto_append_file
no value
no value
auto_globals_jit
On
On
auto_prepend_file
no value
no value
browscap
/etc/browscap.ini
/etc/browscap.ini
default_charset
no value
no value
default_mimetype
text/html
text/html
define_syslog_variables
Off
Off
disable_classes
no value
no value
disable_functions
leak,posix_getpwuid,posix_getpwnam,posix_getgrid,posix_getgrnam,posix_getgroups
leak,posix_getpwuid,posix_getpwnam,posix_getgrid,posix_getgrnam,posix_getgroups
display_errors
Off
Off
display_startup_errors
Off
Off
doc_root
no value
no value
docref_ext
no value
no value
docref_root
no value
no value
enable_dl
Off
Off
error_append_string
no value
no value
error_log
/mnt/Target01/337846/945285/www.dermerrealestate.com/logs/php_errors.log
no value
error_prepend_string
no value
no value
error_reporting
30711
30711
exit_on_timeout
Off
Off
expose_php
Off
Off
extension_dir
/usr/lib64/php/modules
/usr/lib64/php/modules
file_uploads
On
On
highlight.bg
#FFFFFF
#FFFFFF
highlight.comment
#FF8000
#FF8000
highlight.default
#0000BB
#0000BB
highlight.html
#000000
#000000
highlight.keyword
#007700
#007700
highlight.string
#DD0000
#DD0000
html_errors
On
On
ignore_repeated_errors
Off
Off
ignore_repeated_source
Off
Off
ignore_user_abort
Off
Off
implicit_flush
Off
Off
include_path
.:/usr/share/pear:/usr/share/php
.:/usr/share/pear:/usr/share/php
log_errors
On
On
log_errors_max_len
1024
1024
magic_quotes_gpc
On
On
magic_quotes_runtime
Off
Off
magic_quotes_sybase
Off
Off
mail.add_x_header
On
On
mail.force_extra_parameters
no value
no value
mail.log
no value
no value
max_execution_time
30
30
max_file_uploads
20
20
max_input_nesting_level
64
64
max_input_time
60
60
max_input_vars
1000
1000
memory_limit
128M
128M
open_basedir
no value
no value
output_buffering
no value
no value
output_handler
no value
no value
post_max_size
8M
8M
precision
14
14
realpath_cache_size
4M
4M
realpath_cache_ttl
120
120
register_argc_argv
On
On
register_globals
Off
Off
register_long_arrays
On
On
report_memleaks
On
On
report_zend_debug
On
On
request_order
no value
no value
safe_mode
Off
Off
safe_mode_exec_dir
no value
no value
safe_mode_gid
Off
Off
safe_mode_include_dir
no value
no value
sendmail_from
no value
no value
sendmail_path
/usr/sbin/sendmail -t -i
/usr/sbin/sendmail -t -i
serialize_precision
100
100
short_open_tag
On
On
SMTP
localhost
localhost
smtp_port
25
25
sql.safe_mode
Off
Off
track_errors
Off
Off
unserialize_callback_func
no value
no value
upload_max_filesize
8M
8M
upload_tmp_dir
/tmp
/tmp
user_dir
no value
no value
user_ini.cache_ttl
300
300
user_ini.filename
.user.ini
.user.ini
variables_order
EGPCS
EGPCS
xmlrpc_error_number
0
0
xmlrpc_errors
Off
Off
y2k_compliance
On
On
zend.enable_gc
On
On
I have a form that lets a user upload an image, aswell as another file. I want the image to go into the images directory, and the pdf file to go into the PDF directory once uploaded. The names of the files will then be uploaded to the database. At the moment I can get the image to upload to the database and directory, but the PDF is only uploading the name to the database, it is not going into the PDF directory aswell. I'm not sure if there is a way you can do this, I am trying to use "move_uploaded_file()" to physically move the files but not sure if you can use it twice. here is my code, if you can point anything out or where im going wrong that would be great. <?php include "include/conn.php"; include "include/session.php"; ?> <?php // Check to see if the type of file uploaded is a valid image type function is_valid_type($file) { $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif"); if (in_array($file['type'], $valid_types)) return 1; return 0; } function showContents($array) { echo "<pre>"; print_r($array); echo "</pre>"; } //Target path for image $TARGET_PATH = dirname(__FILE__) . "/images/"; //Target path for PDF files $PDF_TARGET_PATH = dirname(_FILE_) . "/PDF/"; // Get POST variables $image = $_FILES['image']; $pdf = $_FILES['pdf']; $date= date("Y-m-d "); $time = date("H:i:s"); $title = $_POST['title']; $title_escape = mysql_escape_string($title); $title_slashes = stripslashes($title_escape); $content = $_POST['content']; $image['name'] = mysql_real_escape_string($image['name']); $pdf['name'] = mysql_real_escape_string($pdf['name']); //image path $TARGET_PATH .= $image['name']; //PDF path $PDF_TARGET_PATH .= $pdf['file_name']; // Make sure all the fields from the form have inputs if ($image['name'] == "" ) { $_SESSION['error'] = "All fields are required"; header("Location: add_media.php"); exit; } // Verify file is an image if (!is_valid_type($image)) { $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header("Location: add_media.php"); exit; } // move file into the directory and the path name into the database / along with the rest of the form fields if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { if(move_uploaded_file($pdf['tmp_name'], $PDF_TARGET_PATH)) { $sql = "INSERT INTO media_table(title, text, time, date, image, PDF) VALUES ('" . $title_slashes . "','" . $content . "', '" . $time . "', '" . $date . "', '" . $image['name'] . "', '" . $pdf['name'] . "')"; $result = mysql_query($sql) or die (mysql_error()); header("Location: add_media.php"); exit; } else { print "did not upload"; } } else { $_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory"; exit; } ?> I am working on getting members that are ready to make a payment after they have logged in and want to view their emails to make the payment first. How can I reprogram my session to stop them from entering the email section and make a payment first. This is my codes which work fine. Just need to know how to amend it to redirect them to payment. <?php //Start session session_start(); //Check whether the session variable SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_ID']) || (trim($_SESSION['SESS_ID']) == '')) { header("location: access-denied.php"); exit(); } ?> $sql = "SELECT * FROM `users` WHERE `emailAddress` = '".mysql_real_escape_string($_POST['email'])."' AND `password` = '".mysql_real_escape_string(md5($_POST['password']))."'"; I currently have it accepting just the email address but I want it to be the email address OR the username. How do I do this? This doesn't seem to be working. Any help? if (isset ($_POST['edit_poser'])){ $errormsg = ""; if (!$_FILES['userfile']['tmp_name']){ $errormsg = "<font style='color: #ff0000;'>Select an Image</font>"; } else { $maxfilesize = 51200; if ($_FILES['userfile']['size'] > $maxfilesize){ $errormsg = "<font style='color: #ff0000;'>Image is too large, select a smaller one</font>"; unlink($_FILES['userfile']['tmp_name']); } else if (!preg_match("/\.(gif|jpg|png)$/i" , $_FILES['userfile']['name'])){ $errormsg = "<font style='color: #ff0000;'>Image needs to be gif, jpg, or png</font>"; unlink($_FILES['userfile']['tmp_name']); } else { $newname = "image01.jpg"; $place_file = move_uploaded_file($_FILES['userfile']['tmp_name'], "Members/$id/".$newname); $errormsg = "<font style='color: #ff0000;'>Your image has successfully been updated</font>"; } } } // ends first if statement I am relatively new to PHP, so I need help why this script is not functioning **T if ($actionis=='Add Resource'){ //declaration of directory where files are saved if(isset($_POST['file'])) { //setting of variables $uploaddir = "resources/"; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fileErr = $_FILES['userfile']['error']; $filePath= $uploaddir . basename($_FILES['userfile']['name']); global $filePath; //filters extension filename $fileX = strrchr($fileName,"."); /* * UPLOAD FILTERING OPTIONS */ if ($fileSize>1000000){ die ("File too large! Must be below 1Mb."); } else{ if (($fileX==".txt")||($fileX==".doc")||($fileX==".docx")||($fileX==".pdf")||($fileX==".ppt")||($fileX==".pptx")){ if (move_uploaded_file($_FILES['userfile']['tmp_name'], $filePath)){ echo "<code>SUCCESS! File Uploaded.</code> ".$fileErr; } else{ echo "<code class='red'>Upload Failed.</code>"; } } else{ die ("Wrong file format!"); } } } The above script does not generate an error. But my problem is that I cannot save the uploaded file into my selected directory. My goal is to allow the user to select whether or not they want to replace the current img files. If so delete all current ones in select dir and upload into it. If not then began uploading at a specific point such that. 1.jpg 2.jpg 3.jpg ... and so on (replace yes deletes all and no deletes none) The directories are assigned previously and are accessed via sql database These are the two current sets i have <?php $page_title = "Central Valley LLC | Photo Addition" ?><?php include("header.php"); ?><?php include("nav.html"); ?> <div id="content"> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="which">Choose A Product:</label> <?php $con = mysql_connect("localhost","phoenixi_cv","centraladmin"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("phoenixi_cvproducts", $con); $result = mysql_query("SELECT * FROM Products"); echo "<select>"; while($row = mysql_fetch_array($result)) { echo "<option "; echo "value=\"" . $row['num'] . "\">"; echo $row['Name'] . "</option>"; } echo "</select>"; mysql_close($con); ?> <br /> <h3 id="center">Do You Wish To Replace Current Images?</h3> <br /> <input type="radio" name="replace" value="y" />YES<br /> <input type="radio" name="replace" value="n" />NO <br /> <input name="uploads[]" type="file" multiple="multiple" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </div><!--#content--><?php include("footer.html") ?>() and this is the upload script so far <?php $count = 1; if($_POST[replace]=='y') { $mydir = 'assets/images/' . $_POST['which'] . '/'; $d = dir($mydir); while($entry = $d->read()) { if($entry!="." && $entry!="..") { unlink($entry); } } } else { $loop = true; while($loop == true) { $filename = 'assets/images/' . $_POST['which'] . '/' . $count . '.jpg'; if(file_exists($filename)) { $count++; } else { $loop = false; } } } if(!is_dir("uploads/".$id)) { //this checks to make sure the directory does not already exist mkdir("uploads/".$id, 0777, true); //if the directory doesn't exist then make it chmod("uploads/".$id, 0777); //chmod to 777 lets us write to the directory } $uploaddir = 'assets/images/' . $_POST['which'] . '/'; foreach($_FILES["uploads"]["name"] as $bla=> $boo) { //we have to do a loop to get all the filenames $file=$uploaddir.$boo; //we will check the filename in the upload directory, see if it exists if (file_exists($file)) { //if it exists then ...... die("Filename already exists, please rename this file"); //if filename exists in the directory then we die!!! :P } } foreach ($_FILES["uploads"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { echo"$error_codes[$error]"; // let you know if there was an error on any uploads move_uploaded_file( //php function to move the file $_FILES["uploads"]["tmp_name"][$key], //from the temporary directory $uploaddir. $_FILES["uploads"]["name"][$key] //to the directory you chose ) or die("Problems with upload"); } } foreach($_FILES["uploads"]["name"] as $bla=> $boo) { $file=$uploaddir.$boo; $movepoint = $uploaddir . $count . '.jpg'; rename($file, $movepoint); $count++; } ?>() Thanks in advance for any help that you can give me.Also if you can suggest any easier ways i would certainly be obliged. I'm looking for ideas thoughts that anyone might have regarding disappearing ID3 tags in .mp3 files after they are uploaded to a web server via $_FILES method. In order, the steps occur at time of upload a 1) File upload is initiated 2) File is uploaded to temp dir on server 3) File is re-assigned a hash value for a file name, with .mp3 appended 4) File is moved from temp dir to the given users dir 5) Meta Data is supposed to be read, and a row inserted into the DB. Now, everything works as intended - not having any issues... Other than, of course, the mystery of the vanishing ID3 tags. Can anyone shed some light on this? I am 100% certain that I can read the meta data - giving two different parameters on two different files (one uploaded manually via sftp, the other via http through the use of $_FILES) Example of what's happening: http://69.164.222.60/test2.php nji.mp3 was uploaded via SFTP. The hashed .mp3 was uploaded via my web form. Thoughts / Comments / Suggestions / Ideas / Saving Grace? ^^ Hi, I want to let users upload multiple images to my online picture book, so after they press submit, HOW do I count the total $_FILES[someName]['name'] uploaded. I want to allow users to type in html form the total uploads they want and this will then display that many desired upload forms. I'm going to try count($_FILES[][]) and go from there first... Any help much appreciated! How to add the ability to login with username or email for login?
<?php ob_start(); include('../header.php'); include_once("../db_connect.php"); session_start(); if(isset($_SESSION['user_id'])!="") { header("Location: ../dashboard"); } if (isset($_POST['login'])) { $email = mysqli_real_escape_string($conn, $_POST['email']); $password = mysqli_real_escape_string($conn, $_POST['password']); $result = mysqli_query($conn, "SELECT * FROM users WHERE email = '" . $email. "' and pass = '" . md5($password). "'"); if ($row = mysqli_fetch_array($result)) { $_SESSION['user_id'] = $row['uid']; $_SESSION['user_name'] = $row['user']; $_SESSION['user_email'] = $row['email']; header("Location: ../dashboard"); } else { $error_message = "Incorrect Email or Password!!!"; } } ?>
Hello. My script is set to upload files upto 5GB large. For that script I've currently set memory_limit to 5GB. Is it alright? I mean what is the ideal value (for large upload scripts) If you feel, 5GB is large. I can make script to upload 2GB files and set memory_limit accordingly. Also, max_execution_time has been set by me to 86400 currently. Assuming, on a 500Kbps broadband, it would require upto 24 hours to upload a 3-5GB file. Please suggest. Thank you. I've got a typical form with an input type="file" for users to upload photos to my site (2mb max to be exact). If you view my code below, you'll notice that I set a variable as the uploaded file's size, and a variable for the max file size I want in bytes. When making sure that the uploaded file's size is LESS than the limit size I set, it should push an error. However, I've noticed that my variable $uploadSize that is supposed to grab the upload file size is only returning "0" (zero). I've tried var_dump($_FILES) to see what was going on and it shows the array with the proper name of the uploaded file, etc. but the file size returns 0. So any file size I upload will bypass my test to see if the file size is less than the limit size. I've tested uploading images 2mb or less and the photos have successfully been queried, moved and resized. However, if I try and upload images LARGER than 2mb, the form still queries all the inputted data into the database but the image isn't successfully moved. I've used this same form and approach on a previous project and I didn't have any trouble. Can I get your guys' eyes on this and see if I'm missing anything small? Code: [Select] <?php if(isset($_POST['submit'])){ // ------------------------------------------------------------- // // A. SET VARIABLES // A1. set variables for inputted data $first = filter_var($_POST['first'], FILTER_SANITIZE_STRING); $last = filter_var($_POST['last'], FILTER_SANITIZE_STRING); $email = filter_var($_POST['email'], FILTER_SANITIZE_STRING); $email2 = filter_var($_POST['email2'], FILTER_SANITIZE_STRING); $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); $description = filter_var($_POST['description'], FILTER_SANITIZE_STRING); // A2. set variables for uploaded submission $uploadPath = $_FILES['uploadFile']['tmp_name']; $uploadSize = $_FILES['uploadFile']['size']; $uploadLimit = 2097152; /* 2mb max file size */ // A3. create error array $errors = array(); // ------------------------------------------------------------- // // B. VALIDATE FIELDS // B1. validate required fields if (empty($first)){ array_push($errors, 'first'); } if (empty($last)){ array_push($errors, 'last'); } if (empty($email)){ array_push($errors, 'email'); } if (empty($email2)){ array_push($errors, 'email2'); } if (empty($name)){ array_push($errors, 'name'); } // B2. validate emails if ($email != $email2){ array_push($errors, 'emailmismatch'); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)){ array_push($errors, 'invalidemail'); } // B3. validate uploaded image file size if ($uploadSize > $uploadLimit){ array_push($errors, 'filesize'); } // ------------------------------------------------------------- // // if no errors, continue query if (sizeof($errors) == 0){ // continue query } } ?> Code: [Select] <form method="post" enctype="multipart/form-data" id="submit-form"> <label for="first">First Name:</label> <input name="first" type="text" value="<?php echo $first; ?>"<?php if(in_array('first', $errors)){ echo ' class="error"'; } ?>> <label for="last">Last Name:</label> <input name="last" type="text" value="<?php echo $last; ?>"<?php if(in_array('last', $errors)){ echo ' class="error"'; } ?>> <label for="email">Email Address:</label> <input name="email" type="text" value="<?php echo $email; ?>"<?php if(in_array('email', $errors)){ echo ' class="error"'; } else if (in_array('emailmismatch', $errors)){ echo ' class="error"'; } ?>> <label for="email2">Confirm Email Address:</label> <input name="email2" type="text" value="<?php echo $email2; ?>"<?php if(in_array('email2', $errors)){ echo ' class="error"'; } else if (in_array('emailmismatch', $errors)){ echo ' class="error"'; } ?>> <br><br><br><br> <label for="name">Your Photo Name:</label> <input name="name" type="text" value="<?php echo $name; ?>"<?php if(in_array('name', $errors)){ echo ' class="error"'; } ?>> <label for="description">Describe The Photo: <span class="optional">(optional)</span> <div class="right"><span class="optional">300 characters max</span></div></label> <textarea name="description" onKeyDown="limitInput(this.form.description,this.form.countdown,300);" onKeyUp="limitInput(this.form.description,this.form.countdown,300);"><?php echo stripslashes($description); ?></textarea> <label for="upload">Photo Image: <span class="optional">(.JPG's only, max 2mb file size)</span></label> <input type="hidden" name="MAX_FILE_SIZE" value="2097152"> <input id="uploadFile" name="uploadFile" type="file"<?php if(in_array('badimage', $errors)){ echo ' class="error"'; } ?> /> <input type="submit" name="submitFeature" class="submit" value="Submit Your Feature"> </form> Awhile ago I wrote a simple form to except image specific uploads from users and chmoded the directory to 777... worked great... Till there was a hack and then I found that chmod 777 is bad So changed the folder to 775, but now the upload script won't work. Can somebody point me to a post or article on how to give a file ownership or group permissions so it can safely run its uploads to the folder? I have tried google but keep getting Linux and Window OS results.. its a tough question to google. Any help is very much appreciated. This upload code is used for uploading a video file from html page, after recording via html5 screen <video></video>, however, ther file doesn't arrive in the uploads/ folder:
<?php foreach (array('video', 'audio') as $type) { if (isset($_FILES["${type}-blob"])) { $fileName = $_POST["${type}-filename"]; $uploadDirectory = 'uploads/' .rand(5,500).$fileName; if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) { echo (" problem moving uploaded file"); } } } when uploaded from iPhone. So, I don't know how to see errors on iPhone. Folder permission is 755. php.ini max file size is 2024M, any ideas/solutions are appreciated.
I have a question,
I have a fully working PHP mail form, but I can't seem to find one problem.
I thought it had something to do with the data cleansing like trim, htmlspecialcharacters and stripslashes, but unfortunately that wasn't.
My form has to be able to process characters like é è á ó etc.
Just that now when you fill those characters in it shows some weird code in the mail.
(é becomes é in the mail) and this is highly inconvenient.
Could any1 tell me how I can fix this?
this is the PHP code for my form: <?php if(isset($_POST['submit'])) { function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $error = ""; //Keep Values $Papillon_checked = (isset($_POST['ras']) && $_POST['ras'] == 'Papillon') ? 'checked' : ''; $Phalene_checked = (isset($_POST['ras']) && $_POST['ras'] == 'Phalene') ? 'checked' : ''; $Babyklasse_checked = (isset($_POST['klasse']) && $_POST['klasse'] == 'Babyklasse') ? 'checked' : ''; $Puppyklasse_checked = (isset($_POST['klasse']) && $_POST['klasse'] == 'Puppyklasse') ? 'checked' : ''; $Jeugdklasse_checked = (isset($_POST['klasse']) && $_POST['klasse'] == 'Jeugdklasse') ? 'checked' : ''; $Tussenklasse_checked = (isset($_POST['klasse']) && $_POST['klasse'] == 'Tussenklasse') ? 'checked' : ''; $Openklasse_checked = (isset($_POST['klasse']) && $_POST['klasse'] == 'Openklasse') ? 'checked' : ''; $Kampioensklasse_checked = (isset($_POST['klasse']) && $_POST['klasse'] == 'Kampioensklasse') ? 'checked' : ''; $Fokkersklasse_checked = (isset($_POST['klasse']) && $_POST['klasse'] == 'Fokkersklasse') ? 'checked' : ''; $Veteranenklasse_checked = (isset($_POST['klasse']) && $_POST['klasse'] == 'Veteranenklasse') ? 'checked' : ''; //Validate form fields if (!empty($_POST['ras'])) { $ras = $_POST['ras']; } else { $error .= "- Klik het ras van uw hond aan. <br />";} if (!empty($_POST['kleur'])) { $kleur = test_input($_POST['kleur']); } else { $error .= "- Vul de kleur van uw hond in. <br />";} if (!empty($_POST['geslacht'])) { $geslacht = test_input($_POST['geslacht']); } else { $error .= "- Vul het geslacht van uw hond in. <br />";} if (!empty($_POST['naamhond'])) { $naamhond = test_input($_POST['naamhond']); } else { $error .= "- Vul de naam van uw hond in. <br />";} if (!empty($_POST['stamboom'])) { $stamboom = test_input($_POST['stamboom']); } else { $error .= "- Vul het stamboomnummer van uw hond in. <br />";} if (!empty($_POST['geboorte'])) { $geboorte = test_input($_POST['geboorte']); } else { $error .= "- Vul de geboortedatum van uw hond in. <br />";} if (!empty($_POST['klasse'])) { $klasse = $_POST['klasse']; } else { $error .= "- Klik de gewenste klasse aan. <br />"; } if (!empty($_POST['fokker'])) { $fokker = test_input($_POST['fokker']); } else { $error .= "- Vul de naam van de fokker in. <br />";} if (!empty($_POST['vader'])) { $vader = test_input($_POST['vader']); } else { $error .= "- Vul de naam van de vaderhond in. <br />";} if (!empty($_POST['moeder'])) { $moeder = test_input($_POST['moeder']); } else { $error .= "- Vul de naam van de moederhond in. <br />";} if (!empty($_POST['initialen'])) { $initialen = test_input($_POST['initialen']); } else { $error .= "- Vul uw initialen in. <br />";} if (!empty($_POST['eigachternaam'])) { $eigachternaam = test_input($_POST['eigachternaam']); } else { $error .= "- Vul uw achternaam in. <br />";} if (!empty($_POST['minitialen'])) { $minitialen = test_input($_POST['minitialen']);} if (!empty($_POST['meigachternaam'])) { $meigachternaam = test_input($_POST['meigachternaam']);} if (!empty($_POST['straat'])) { $straat = test_input($_POST['straat']); } else { $error .= "- Vul uw straatnaam in. <br />";} if (!empty($_POST['huisnr'])) { $huisnr = test_input($_POST['huisnr']); } else { $error .= "- Vul uw huisnummer in. <br />";} if (!empty($_POST['postcode'])) { $postcode = test_input($_POST['postcode']); } else { $error .= "- Vul uw postcode in. <br />";} if (!empty($_POST['plaats'])) { $plaats = test_input($_POST['plaats']); } else { $error .= "- Vul uw woonplaats in. <br />";} if (!empty($_POST['land'])) { $land = test_input($_POST['land']);} if (!empty($_POST['email'])) { $email = $_POST['email']; if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)){ $error .= "- U heeft een ongeldig e-Mail adres ingevuld. <br/>";} } else { $error .= "- Vul uw e-Mail adres in. <br />";} if (!empty($_POST['telefoon'])) { $telefoon = test_input($_POST['telefoon']);} if (!empty($_POST['peradres'])) { $peradres = test_input($_POST['peradres']);} if (!empty($_POST['eerstehond'])) { $eerstehond = test_input($_POST['eerstehond']);} if (!empty($_POST['verderehond'])) { $verderehond = test_input($_POST['verderehond']);} if (!empty($_POST['babypup'])) { $babypup = test_input($_POST['babypup']);} if (!empty($_POST['koppelklas'])) { $koppelklas = test_input($_POST['koppelklas']);} if (!empty($_POST['koppelhond1'])) { $koppelhond1 = test_input($_POST['koppelhond1']);} if (!empty($_POST['koppelhond2'])) { $koppelhond2 = test_input($_POST['koppelhond2']);} if (!empty($_POST['totaal'])) { $totaal = test_input($_POST['totaal']);} if (!empty($_POST['naamjh'])) { $naamjh = test_input($_POST['naamjh']);} if (!empty($_POST['leeftijdjh'])) { $leeftijdjh = test_input($_POST['leeftijdjh']);} if (!empty($_POST['akkoord'])) { $akkoord = $_POST['akkoord']; } else { $error .= "- U moet akkoord gaan met de voorwaarden voordat u het bericht kunt versturen. <br />";} //no errors were set if(empty($error)) { //code to send the email //The form has been submitted, prep a nice thank you message $output = '<center><b>Het Inschrijfformulier is verzonden <br />We zullen de gegevens verwerken <br/><u>Papillon & Phalène Vereniging Nederland</u></b></center>'; //Set the form flag to no display (cheap way!) $flags = 'style="display:none;"'; //Deal with the email $to = 'joke@pp-vn.nl'; $from = $_POST['email']; $subject = 'Inschrijfformulier'; $message = 'From: ' .$initialen .' ' .$eigachternaam . ' <' . $email . '>' ."\n\n"; $message .= 'Ras: ' .$ras ."\n"; $message .= 'Kleur: ' .$kleur ."\n"; $message .= 'Geslacht: ' .$geslacht ."\n"; $message .= 'Naam v/d hond: ' .$naamhond ."\n"; $message .= 'Stamboomnummer: ' .$stamboom ."\n"; $message .= 'Geboortedatum: ' .$geboorte ."\n"; $message .= 'Klasse: ' .$klasse ."\n"; $message .= 'Naam Fokker: ' .$fokker ."\n"; $message .= 'Naam Vaderhond: ' .$vader ."\n"; $message .= 'Naam Moederhond: ' .$moeder ."\n"; $message .= 'Eigenaar: ' .$initialen .' ' . $eigachternaam ."\n"; $message .= 'Mede-eigenaar: ' .$minitialen .' ' .$machternaam ."\n"; $message .= 'Adres: ' .$straat .' ' .$huisnr .' ' .$postcode .' ' .$plaats .' ' .$land ."\n"; $message .= 'Telefoon: ' .$telefoon ."\n"; $message .= 'e-Mail: ' .$email ."\n"; $message .= 'Per Adres: ' .$peradres ."\n"; $message .= 'Inschrijving eerste hond: ' .$eerstehond . "\n"; $message .= 'Andere honden ingeschreven: ' .$verderehond . "\n"; $message .= 'Baby- Puppyklasse: ' .$babypup . "\n"; $message .= 'Koppelklasse: ' .$koppelklas . "\n"; $message .= 'Koppelklasse Hond 1: ' .$koppelhond1 . "\n"; $message .= 'Koppelklasse Hond 2: ' .$koppelhond2 . "\n"; $message .= 'Totaalbedrag: ' .$totaal . "\n"; $message .= 'Naam Juniorhandler: ' .$naamjh . "\n"; $message .= 'Leeftijd Juniorhandler: ' .$leeftijdjh . "\n"; $message .= 'Akkoord: ' .$akkoord ."\n"; $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name']))); $filename = $_FILES['file']['name']; $boundary =md5(date('r', time())); $headers = "From: fransien@pp-vn.nl"; $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\""; $message="This is a multi-part message in MIME format. --_1_$boundary Content-Type: multipart/alternative; boundary=\"_2_$boundary\" --_2_$boundary Content-Type: text/plain; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit $message --_2_$boundary-- --_1_$boundary Content-Type: application/octet-stream; name=\"$filename\" Content-Transfer-Encoding: base64 Content-Disposition: attachment $attachment --_1_$boundary--"; mail($to, $subject, $message, $headers); mail($from, $subject, $message, $headers); } else { //display errors echo '<center><span class="error"><strong>Uw bericht is niet verstuurd<br/> De volgende fout(en) zijn opgetreden:</strong><br/>' . $error . '<br /><strong><u>Pas op: Bij een foutmelding indien nodig Kampioenstitel opnieuw toevoegen!!</u></strong></span></center>'; } } ?> I have a file upload script that will eventually process a ton of files. I would like to upload them into sub-directories according to what year, month, and day they are uploaded.
A typical tree should look like this:
attachments/
--/2014
-----/January
--------/01
--------/02
--------/03 , etc.
-----/February
--------/01
--------/04
--------/09
--------/18
--------/20, etc
-----/March, etc
--/2015, etc.
So a file called image.jpg uploaded on 10/31/2014 would have a URL of attachments/2014/October/31/image.jpg. I understand that every time a file is uploaded, the script would have to detect through FTP whether or not folders for the year, month, and day exist, and if they don't create them. My problem is that I have no idea what the logic of this script would be. What order should I do things in? Is there a way to use maybe foreach to detect/create the folders? Any input would be appreciated.
Hi all I have a script that I have patched together and got to work in pieces. I'm up to the last part. I have the form working and emailing. It also will upload an image by itself and put it in a folder. Now i just need to tie those together and have the image put in the email as an attachment then deleted from server. I have it at a stage where it sends me the users details.. and it tries to send the photo but it comes through as junk txt. I think its the MIME encoding stuff that I have wrong.. not sure? Here's what I have so far. Code: [Select] $attachment = $path_of_uploaded_file; $fileatt = $attachment; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1; $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers = "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; // create email headers $headers .= 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); Thanks Wolfsta I am attempting to get my email form with file attachment to work. Apparently the file is not reaching getting to the validation portion of the page I have switched $_FILES['X'] on line 203 from file to fakefile as they are labeled in the form also I am employing css hacks to change the input file upload field to have a custom button example -> http://visualrealityink.com/dev/clients/arzan/snell_form_final/form.php here is my code I appreciate any help Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> #form_container{ display:block; position:absolute; width:610px; min-height:450px; background:#f8f8f8; padding: 5px 5px 5px 5px; font-family:Arial, Helvetica, sans-serif; font-size:14px; } #form { min-height:450px; width:100%; background:#ececec; padding:0 0 0 0; } #formheader { background:url(images/form2_08.png) no-repeat #2f2f2f; margin:0 0 0 0; padding:0 0 0 0; width:631; height:30px;} form{margin:35px 0 0 35px;} fieldset div { margin:0.3em 0; clear:both; } label { float:left; width:10em; text-align:left; margin-right:1em; font-family:Arial, Helvetica, sans-serif; font-size:14px; } input { padding:0.15em; margin:0 0 0 -110px; width:300px; background:url(images/inputbg.png) no-repeat; border:0px solid #ddd; background:#fafafa; -moz-border-radius:0.4em; -khtml-border-radius:0.4em; } .bg2{background:url(images/inputbg.png) no-repeat; height:28px; line-height:28px;} fieldset { border:0px solid #ddd; padding:0 0.5em 0.5em; margin:0 0 0 -100px; } #details{font-size:10px;} #logo{background:url(images/form2_11.png) no-repeat; width:189px; height:238px; margin:-200px 0 0 400px; position:absolute;} #submit{margin:14px 0 0 -5px; border:none; position:absolute; cursor:pointer; cursor:hand;} #reset{border:none; margin:14px 0 0 115px; position:absolute; cursor:pointer; cursor:hand; } #divinputfile{ background:url(images/form2_27.png) no-repeat 100% 1px; height:43px; line-height:43px; width:340px; }#divinputfile #filepc{ opacity: 0.0; -moz-opacity: 0.0; filter: alpha(opacity=00); font-size:18px; margin:0 0 0 0; cursor:hand; cursor:pointer; } #fakeinputfile{ margin-top:-28px; } #fakeinputfile #fakefilepc{ background:url(images/inputbg2.png) no-repeat; style:none; width:240px; height:28px; line-height:28px; border:0; margin:5px 0 0 0; font-size:18px; font-family:Arial; } button { cursor: hand; cursor: pointer; padding: 0px; margin: 0 0 0 0; } a.link_button{ cursor: hand; cursor: pointer; } .fileupload{ margin:0 0 0 50px; } input[type="file"] { cursor: pointer; } .error{font-size:9px; font-family:Arial, Helvetica, sans-serif; color:#F00; } .error ul { text-decoration: none; list-style: none; } .error li { color: #F00;} .captcha_form { margin: 0 0 0 -45px; width:235px; } #captchaimage{ padding:0 0 10px 0;} .small { font-size:9px;} </style> </head> <body> <?php if ($_POST['_submit_check']) { // If validate_form( ) returns errors, pass them to show_form( ) if ($form_errors = validate_form()) { show_form($form_errors); } else { // The submitted data is valid, so process it process_form(); } } else { // The form wasn't submitted, so display show_form(); } function show_form($errors = '') { // If the form is submitted, get defaults from submitted parameters if ($_POST['_submit_check']) { $defaults = $_POST; } else { // Otherwise, set our own defaults: medium size and yes to delivery $defaults = array('IssueDate' => '','ExpiryDate' => ''); } if ($errors) { $error_text = 'You need to correct the following errors:'; $error_text .= '<br /><ul>'; $error_text .= implode('<li>',$errors); $error_text .= '</li></ul>'; } else { // No errors? Then $error_text is blank $error_text = ''; } include 'formhelpers.php' ?> <div id="form_container"> <div id="form"> <br /> <div id="formheader"> </div> <form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <span class="error"> <?php print $error_text ?> </span> <input type="hidden" name="_submit_check" value="1"/> <div> <label for="name">Name: </label> <?php input_text('name', $defaults) ?> </div> <div> <label for="email">Email:</label> <?php input_text('email', $defaults) ?> </div> <div> Attach Resume: <span class="small">(1MB : PDF : DOC : DOCX : TXT)</span> </div> <div> <!--<input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <label for="userfile"></label> <input type="file" name="userfile" id="userfile"/> </div>--> <div id="divinputfile"> <input name="file" type="file" size="30" id="filepc" onchange="document.getElementById('fakefilepc').value = this.value;"/> <div id="fakeinputfile"> <input name="fakefile" type="text" class="link_button" id="fakefilepc" /> </div> </div> <div id="captchaimage"><img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /></div> <div><label for="email"><a style="text-decoration: none" href="#" onclick="document.getElementById('captcha').src = 'securimage/securimage_show.php?' + Math.random(); return false">New Captcha: </a></label> <input type="text" name="captcha_code" class="captcha_form" size="10" maxlength="6" /> </div> <button type="submit" value="submit" id="submit" ><img src="images/form2_33.png" /></button> <button type="reset" value="reset" id="reset" ><img src="images/form2_37.png" /></button> </form> </div> <div id="logo"></div> </div> </div> <?php } function validate_form() { $errors = array( ); // name is required if ($_POST['name'] == "") { $errors[ ] = 'Please enter your name.'; } if (! strlen(trim($_POST['email']))) { $errors[ ] = 'Please enter your Email.'; } if (! preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $_POST['email'])) { $errors[ ] = 'Please enter a valid e-mail address'; } $filename=$_FILES['file']['name']; //For size if($_FILES["file"]["size"]>1000000) //1 mb { $errors[ ] = "File size should be less than 1MB"; } // for extention $ext = end(explode('.', $filename)); if($ext=='doc' || $ext=='txt' || $ext=='pdf' || $ext=='docx' ) { echo "write the code to upload file"; $max_allowed_file_size = 1024; // size in KB $name_of_uploaded_file = basename($_FILES['file']['name']); //get the file extension of the file $type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file = $_FILES["file"]["size"]/1024;//size in KBs //copy the temp. uploaded file to uploads folder $upload_folder = 'upload/'; $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; $tmp_path = $_FILES["file"]["tmp_name"]; if(is_uploaded_file($tmp_path)) { if(!copy($tmp_path,$path_of_uploaded_file)){ echo 'error while copying the uploaded file'; die(); } } } else { $errors[ ] = "Only doc or pdf or txt file is allowed: $filename "; } return $errors; } function process_form() { $image = "http://www.visualrealityink.com/dev/clients/arzan/snell_form/images/email.png"; include_once('Mail.php'); include_once('Mail_Mime/mime.php'); $to = 'george@visualrealityink.com'; $text = $image . "<br />" . $values['name'] . "submitted a resume on our website. Please review the applications and contact the candidate if their resume is a fit for any open opportunities with the company. <br><br> Thank you. <br><br> SEI Team"; $message=new Mail_mime(); $message=setTXTBody($text); $message=addAttachment($path_of_uploaded_file); $body = $message->get(); $extraheaders = array("From"=>$formValues['email'], "Subject"=>$subject, "Reply-To"=>$formValues['email']); $headers = $message->headers($extraheaders); $mail = Mail::factory("mail"); $mail->send($to, $headers, $body); echo "email sent"; } ?> </body> </html> |