This is complete request form and it can be used to ‘Request A Quote’ and have some material from user uploaded at your server. This is what script does.

Functionality

- Determines Max File Size (Size Restriction)
- Determines Max Available Space for upload (Space Restriction)
- Stores the file in predefined directory at your server
- Emails you a path to the link of recent uploaded file with other details

Variables Used In Form

$Name
$Speciality
$Email
$Phone
$Fax
$Clinic
$uploadedfile
$info

PHP Code For File Upload

<?php
$MaxFileSize = "2048000"; // max file size in bytes
$HDDSpace = "1048576"; // max total size of all files in directory
$HDDTotal = "445";
$OffExt = "";
// add characters to strip out of filenames
$ThisFileName = basename(__FILE__); // get the file name
$abspath = str_replace($ThisFileName,"",__FILE__);   // get the directory path
// full path
$path=$abspath;
$pathext="upload/";
$snr = array("%","'","+","\\","/","#","..","!",'"',',','?','*','~');
$temp=$HTTP_POST_FILES['uploadedfile']['name'];
 
if($HTTP_POST_FILES['uploadedfile']['name'])
{
 $HTTP_POST_FILES['uploadedfile']['name'] = strip_tags($HTTP_POST_FILES['uploadedfile']['name']);
 $HTTP_POST_FILES['uploadedfile']['name'] = str_replace($snr,"",$HTTP_POST_FILES['uploadedfile']['name']);
// remove any % signs from the file name
 $HTTP_POST_FILES['uploadedfile']['name'] = trim($HTTP_POST_FILES['uploadedfile']['name']);
 
 /* if the file size is within allowed limits */
 if($HTTP_POST_FILES['uploadedfile']['size'] > 0 && $HTTP_POST_FILES['uploadedfile']['size'] < $MaxFileSize)
			{
  /* if adding the file will not exceed the maximum allowed total */
  if(($HDDTotal + $HTTP_POST_FILES['uploadedfile']['size']) < $HDDSpace)
				{
 
  /* put the file in the directory */
move_uploaded_file($HTTP_POST_FILES['uploadedfile']['tmp_name'], $path.$pathext.$HTTP_POST_FILES['uploadedfile']['name'].$OffExt);
$msg = "The file ".$HTTP_POST_FILES['uploadedfile']['name']." is Successfully uploaded ";
 
		$myfrom = $Email;
		$myemail = "youremail@hotmail.com";
		$todayis = date("l, F j, Y, g:i a") ;
$filename="http://www.sitename.com/".$pathext.$HTTP_POST_FILES['uploadedfile']['name'].$OffExt;
		$filename=str_replace("","%20",$filename);
 
		$subject= "Request From Website";
 
		$message = "
		uploadedfile  	        : $filename
		Name          	        : $Name
		Email         	          : $Email
		Phone         	         : $Phone
		Fax           	          : $Fax
		Speciality    	         : $Speciality
		Clinic/Hospital          :$Clinic
		Comments/Request   :$info
		";
		$from = "From: $myfrom\r\n";
		mail($myemail, $subject, $message, $from);
	                }
                else
			{
$msg = "The Filename: ".$HTTP_POST_FILES['uploadedfile']['name']." is BLOCKED from being uploaded here.";
                }
 
		}
        else
		{
        $MaxKB = $MaxFileSize/1024;
        // show the max file size in Kb
        $msg =  "The file was greater than the maximum allowed, file size of $MaxKB and could not be uploaded.";
	    }
	}
print $msg;
?>

Precautions

  • CHMOD ‘upload’ folder to 777 if it is at online server
  • Use enctype=”multipart/form-data” in form tag

Upload File With Restrictions And Email Script Download

  • Share/Bookmark

2 Reviews

  1. dupreelove says:

    Hi

    Got the upload work and the forms sends a notfication to my email, but I don’t get the messages, which I put into the form?! I modified the form a bit, so that it is only “Name”, “Email” and “Info” that is to be filled out – does this require a rewriting of the php?

  2. Mike says:

    Hi,

    Just wanted to says thanks for the awesome script. I was able to rewrite the code to my liking for what I needed. But I was wondering why if you don’t put something in the upload and send it as a regular email it doesn’t send?Well is says it sends but never shows up in my inbox.But if I have an attachment it sends fine with the message.

Leave a Review

Incoming Searches

php file upload email, Upload File in PHP with email alert, upload file and send email php, php email upload, Email Image Upload, upload and email php, upload and email images PHP, php upload image par email, php upload image and email it, php upload mail, php upload image and email, php upload script that send email, php upload script with email notification, php upload form with image send mail, php to upload and email a file, php upload form with email notification, php upload and email, php upload and email file, php upload and send email, php upload email, php upload email notification, php upload file by email, php upload file email, php upload file mailen, php upload file restrictions, php upload file to email, Restriction on form php if space, send email and upload picture php, trim uploaded file, upload files and email php script, upload files email address php, upload files email php, upload image and send it in email php, upload image by email php, upload image php email, upload picture by email php, upload to email php form, uploaded files in email php, upload file to server and mail link in email in php, upload file php email, upload & send to email php, upload and email file php, upload and email image php form, upload and email using php, upload by email PHP, upload by email script, upload email php, upload file in php and send in email, upload file path to mail php, uploading images to email using php, $HTTP_POST_FILES, form file upload email php, form php upload email, form upload and email file php, formulario upload file email php, get the full path from uploaded file using php, how can we upload and mail attached file in php, how to add file and email it in php, how to add restrictions in php upload file?, how to put the restrictions when uploading in case of the php file, file upload type restrictions php, file submission form php email, facebook email upload link, $HTTP_POST_FILES checks, attach uploaded file in email php, doesnt upload email file facebook, easy php image upload email attach, email file attachment using php, email file upload php script, email php form upload, email uploded files php, facebook email php upload, how to send uploded image in mail using php, how to upload and mail a file using PHP, image upload on email php, php file upload mail, php form and file upload email, php form email uploaded file, php form file upload email, php form upload array files, php form upload file restrictions, php guestbook image upload -Advanced -slideshow -hosting, php mail image, php mail notification when upload image, php file upload form and send email, php file upload and email, php email uploaded file, image upload php send email, images/email php 2010, mail uploaded files php, mailing a uploaded file in php, php add file upload to email, php code to upload a file with date restriction, php email file upload, php email notification after upload, php email upload file headers, php script file upload mail