Home     License     Free Quote     Payment     Contact Us   Tutorial    Links    Web Hosting
PHP Spam Terminator
Demo
4MemberOnly
Demo
F.A.Q
Tutorial
Commercial Licence
USZip Digger
US ZipCode Scripts
Database Snapshots
ezFAQ
Demo
Live ezFAQ
Tutorial
IPWhereRU
Excel2HTML
4MemberOnly - Template
Demo
Shopping Cart
 
How to let your customers or visitors easily put files on your server.

To enable customers to upload file on your server is very easy. Only three steps:

1, Create a directory for uploading files and change directory permissions to 777

2, Here is the php code for uploading files. You may want to take a look Demo http://knc.com/upload_art/upload_art.php

<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="upload_art_process.php" name="catalog_form" onsubmit="return checkCatalogForm();">
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
<table width="100%" border="0">
<tr>
<td width="24%" align="right"><font color="#FF0000">* </font>Name:</td>
<td width="76%"><input type="text" name="bio_name" size="50"></td>
</tr>
<tr>
<td align="right"><font color="#FF0000">*</font> Email:</td>
<td><input type="text" name="bio_email" size="50"></td>
</tr>
<tr>
<td height="26" align="right"><font color="#FF0000">*</font> Telephone:</td>
<td><font face="Arial, Helvetica, sans-serif">
<input type="text" name="bio_telephone" size="50">
</font></td>
</tr>
<tr>
<td height="43" align="right"><font color="#FF0000">* </font>File
1: </td>
<td> <input type="FILE" name="file1" size="50">
<br>
<font color="#FF0000">(File name cannot include spaces and other
invalid characters) </font> </td>
</tr>
<tr>
<td align="right">Comments</td>
<td><font face="Arial, Helvetica, sans-serif">
<textarea name="bio_comments" cols="40" rows="4"></textarea>
</font></td>
</tr>
<tr>
<td align="right">&nbsp;</td>
<td><font face="Arial, Helvetica, sans-serif">
<input name="SUBMIT" type="SUBMIT" value="Upload">
</font></td>
</tr>
</table>
</FORM>

3, Here is the process php script

<?php
$user_name = $_POST["bio_name"] ;
$user_email = $_POST["bio_email"] ;
$user_phone = $_POST["bio_telephone"] ;
$todays_date = date("Ymd");

$headers = "From: " . $email ;
$subject = 'User '. $user_name .' has uploaded a file on www.knc.com. Please check!' ;

$msg="Customer information: ";
$msg=$msg . "\r\n Name: $user_name" ;
$msg=$msg . "\r\n Email: $user_email " ;
$msg=$msg . "\r\n Telephone: $user_phone " ;
$msg=$msg . "\r\n Download URL: http://www.knc.com/upload_art/upload_art_files/" . $todays_date. '_' . $_FILES['file1']['name'] ;

$recipient = "xxxx@xxxx.com";

mail($recipient, $subject, $msg, $headers);

$uploaddir = '../upload_art/upload_art_files/';
$uploadfile = $uploaddir . $todays_date . '_' . $_FILES['file1']['name'];

print "<pre>";
if (move_uploaded_file($_FILES['file1']['tmp_name'], $uploadfile))
{
print "Upload successfully! Thank you for uploading art. ";
//print "Here's some more debugging info:\n";
//print_r($_FILES);
} else {
print "Upload failed! Please try it again!";
//print_r($_FILES);
}
print "</pre>";
?>

If you want to restrict the file format (you don't want to people upload a virus to your server), use javascript to validate the file format

<script language="JavaScript">
function checkCatalogForm(obj)
{
var regex = /^[A-Za-z_0-9'\.\-]+@[A-Za-z_0-9'\.\-]+(\.\w+)+$/;
var emailTest = regex.exec(document.catalog_form.bio_email.value);

if(document.catalog_form.bio_name.value == '')
{
alert( "You must supply a name. " );
document.catalog_form.bio_name.focus();
return false;
}
else if(!emailTest)
{
alert("You must supply a valid email address.");
document.catalog_form.bio_email.focus();
document.catalog_form.bio_email.value = '';
return false;
}
else if(document.catalog_form.bio_telephone.value == '')
{
alert( "You must supply a telephone. " );
document.catalog_form.bio_telephone.focus();
return false;
}
else if(document.catalog_form.file1.value == '')
{
alert( "You must supply a file. " );
document.catalog_form.file1.focus();
return false;
}
else if(document.catalog_form.file1.value.lastIndexOf(".jpg") > -1 )
{
return true;
}
else if(document.catalog_form.file1.value.lastIndexOf(".JPG") > -1 )
{
return true;
}
else
{
alert( "You must supply a valid image file format. We accept following formats: eps, cdr , ai, pdf, emf, jpg,jpeg, gif, bmp, and tiff" );
document.catalog_form.file1.focus();
return false;
}
}
</script>


Copyright © 2003-2007, GDSLand.com - Great Design & Source LLC :: Refund Policy :: Privacy Policy ChemMol.com
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z