Right now I have a script that will allow a webuser to upload a file to my webserver if it meets certain conditions... however, id like to email that file somewhere instead of uploading it to the server using the mail() function but have no idea how to do attachments stuff....
heres my functional upload script:
<center><h3>Upload Drawings</h3><br />
<table align="left" id="uploadform" cellpadding="2" cellspacing="2">
<form name="upload" ENCTYPE="multipart/form-data" method="post">
<tr>
<td colspan="2">
<?php
//These are for if u wanna spit out a link to the file after
//shiznuts is complete --commented out--
/*$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];*/
$upload_dir = "upload_files/";
$upload_url = $url_dir."/upload_files/";
$message ="";
//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("upload_files")) {
die ("upload_files directory doesn't exist");
}
if ($_FILES['userfile']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "Please Select a Valid File.<br />";
$message .= "Valid Filetypes Are: <b>.dwg</b>, <b>.zip</b><br />";
$message .= "Maximum Filesize is: <b>10MB (megabytes)</b>";
}
print $message;
function do_upload($upload_dir, $upload_url) {
$password = $_REQUEST['password'];
$user_ip = $_SERVER['REMOTE_ADDR'];
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $user_ip."@".$_FILES['userfile']['name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
$file_ext = substr($file_name, -3);
$allowed_types = array('dwg','zip');
$accepted_pw = 'cad2005';
//Pasword Check
if ($password =="")
{
$message = "<b>Please Enter a Password</b>";
return $message;
}
elseif ($password !== $accepted_pw)
{
$message = "<b>The Password You Have Specified is Invalid</b>";
return $message;
}
//File Name Check
elseif ( $file_name =="")
{
$message = "<b>Invalid File Name Specified.</b>";
return $message;
}
//File Size Check
else if ( $file_size > 10000000)
{
$message = "<b>The File Size is Over 10MB.</b>";
return $message;
}
elseif (!in_array($file_ext, $allowed_types))
{
$message = "<b>Sorry, That Filetype is Invalid.</b>";
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"Success!" :
"Unknown Error While Uploading File.<br />
Please Contact The Person Who Refered You Here For Assistance.";
//Shiznuts for printing the link out
/*$message = ($result)?"File url <a href=$file_url>$file_url</a>" :
"Somthing is wrong with uploading a file.";*/
return $message;
}
?>
<br /><br />
</td>
</tr>
<tr>
<td align="left">Password:</td>
<td><input type="text" id="password" name="password">
<img src="images/help.gif" align="absbottom" onMouseover="ddrivetip('Password REQUIRED:<br />If you do not have a password<br />you will need to contact us at:<br /><b>518-399-9162 Ext. 184</b>')"; onMouseout="hideddrivetip()" alt=""/>
</td>
</tr>
<tr>
<td align="left">Upload File:</td>
<td><input type="file" id="userfile" name="userfile"> <input type="submit" name="upload" value="Upload">
<img src="images/help.gif" align="absbottom" onMouseover="ddrivetip('Click BROWSE to locate the file<br />Click UPLOAD to submit the file')"; onMouseout="hideddrivetip()" alt=""/>
</td>
</tr>
<tr>
<td colspan="2"><br />Your IP has been logged: <b><?php echo $_SERVER['REMOTE_ADDR']; ?></b></td>
</tr>
</form>
</table>
</center>
any help would be appreciated.. thanx!