Ok so to get around this problem I want to give the user the option to email the selected file from the dropdown list to the email address which the user enters in a text field then clicks the 'Email' submit button.
This is the script for my form: -
<?php
//if the form has been submitted, display result
if (isset($result))
{
echo "<p>$result</p>";
}
?>
<form action="" method="post" enctype="multipart/form-data" name="filemanage" id="filemanage">
<fieldset>
<legend>Upload file section</legend>
<table>
<tr>
<td>
<label for="upload">Upload file:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
<input type="file" name="upload" id="upload" />
<input type="submit" name="Upload" id="Upload" value="Upload" />
</td>
</tr>
</table>
</fieldset>
</form>
<form action="" method="post" name="filemanage" id="filemanage">
<fieldset>
<legend>Download file section</legend>
<table>
<tr>
<td>
<label for="download">Download file:</label>
<select name="download" id="download">
<option value="">Select a file</option>
<?php
include('includes/dropdown_menu.inc.php');
dropdown("$foldername");
?>
</select>
<input type="submit" name="Download" id="Download" value="Download" />
<input type="text" name="email" id="email" />
<input type="submit" name="Email" id="Email" value="Email" />
</td>
</tr>
</table>
</fieldset>
</form>[/B]
This is the include script which controls the download of the selected file: -
<?php
if (array_key_exists('Download', $POST))
{
$getfile = ($POST['download']);
// define the pathname to the file
$filepath = "$foldername".$getfile;
$ext = substr($filepath, strrpos($filepath, '.')+1);
switch ($ext)
{
case 'pdf':
$type = 'application/pdf';
break;
case 'jpg':
case 'jpeg':
$type = 'image/jpeg';
break;
case 'xls':
$type = 'application/vnd.ms-excel';
break;
case 'doc':
$type = 'application/vnd.ms-word';
break;
}
// check that it exists and is readable
if (file_exists($filepath) && is_readable($filepath)) {
// get the file's size and send the appropriate headers
$size = filesize($filepath);
header('Content-Type: '.$type);
header('Content-Length: '.$size);
header('Content-Disposition: attachment; filename=' .$getfile);
header('Content-Transfer-Encoding: binary');
// open the file in binary read-only mode
$file = @ fopen($filepath, 'rb');
if ($file) {
// stream the file and exit the script when complete
fpassthru($file);
exit;
}
}
}
?>[/B]
What would I need to add to this script so that when the user enters an email address in the 'Email' field & clicks the 'Email' submit button it emails the selected file?
I appreciate this is probably a tricky one but any help would be greatfully recieved.