php mail: insert uploaded filenames into field
Posted: Tue Aug 16, 2011 12:09 pm
hi everyone.
i have a form which allows multiple attachments to be sent with an email. i can insert a single filename into a db like so:
however, i allow multiple attachments with the following code:
i need to insert filenames into mysql into a single field like so:
filename1.ext, filename2.ext, filename3.ext, etc
i'm unsure how to do that. does anyone have any ideas or links which may assist me? Thanks.
i have a form which allows multiple attachments to be sent with an email. i can insert a single filename into a db like so:
Code: Select all
<?php
$target_path = $target_path . basename($filename = $_FILES['resume']['name']);
$query = "INSERT INTO `attachments` VALUES ('$date', '$time', '$filename')";
$result = mysql_query($query) or die();
?>
Code: Select all
<?php
foreach($_FILES as $userfile) {
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = basename($userfile['name']);
$size = $userfile['size'];
if (file_exists($tmp_name)) {
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)) {
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
$uploaddir = 'upload/';
// generate a set of 6 random characters and append it to the filename incase a file with the same
// name already exists.
$seed_array = array_merge(range('A','Z'),range(0,9));
$rand_ary = array_rand($seed_array,6);
$rand_str = '';
foreach($rand_ary as $rk)
$rand_str .= $seed_array[$rk];
$fileName = $rand_str . '-' . $name;
move_uploaded_file($tmp_name, $uploaddir.str_replace(' ', '_', $fileName));
fclose($file);
$data = chunk_split(base64_encode($data));
}
}
?>
filename1.ext, filename2.ext, filename3.ext, etc
i'm unsure how to do that. does anyone have any ideas or links which may assist me? Thanks.