我有一个简单的html表单,它发送一个包含多个附件的电子邮件(最多5个)。我正在保存电子邮件,地址在phpadmin中。现在我想保存多个附件。 如何保存多个附件,然后在另一页上重新打开。
我使用phpmailer发送电子邮件和附件,发送附件的循环是:
$MyUploads = array();
foreach(array_keys($_FILES['attach']['name']) as $key)
{
$filesize = $_FILES['attach']['size'][$key];
$extention = pathinfo ($_FILES['attach']['name'][$key] ,PATHINFO_EXTENSION );
$name=$_FILES['attach']['name'][$key];
$filePath = $Location . $name;
$tmpName = $_FILES['attach']['tmp_name'][$key];
if(move_uploaded_file($tmpName, $filePath))
{$MyUploads[] = $Location;}
else
{$MyUploads[]='';}
print_r($MyUploads);
$source = $_FILES['attach']['tmp_name'][$key];
$filename = $_FILES['attach']['name'][$key];
$mail->AddAttachment($source, $filename);
}
将这些文件位置插入数据库的查询是
$insert = "INSERT INTO upload (name, type, size, file1, file2, file3, file4, file5,
created) VALUES
(
'".$name."',
'".$extention."',
'".$filesize."',
'".$MyUploads[0]."',
'".$MyUploads[1]."',
'".$MyUploads[2]."',
'".$MyUploads[3]."',
'".$MyUploads[4]."' ,
now()
)";
$result = $dbLink->query($insert);
请现在我如何在另一个php页面上检索这些文件。请我是初学者,所以任何一个人。
答案 0 :(得分:2)
这已在此多次回答..请参阅
multi image upload wrong quantity on file-upload
limiting the checking condition while uploading swf files
编辑1
我认为你的桌子应该是什么样的
CREATE TABLE IF NOT EXISTS `upload` (
`uploadID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`uploadExt` varchar(10) NOT NULL,
`uploadSize` varchar(50) NOT NULL,
`uploadPath` varchar(200) NOT NULL,
`uploadName` varchar(100) NOT NULL,
PRIMARY KEY (`uploadID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
如何插入
$mysql = new mysqli("localhost","root","","test");
$sql = "INSERT INTO `upload` (
`uploadID` ,
`uploadExt` ,
`uploadSize` ,
`uploadPath` ,
`uploadName`
)
VALUES (
NULL , '%s', '%s', '%s', '%s');"
foreach($image_you_have_uploaded as $valid) /// Am sure you know what this is
{
//Make sure you mysql_real_escape_string everthing
$mysql->query(sprintf($sql,$extention,$filesize,$filePath,$name));
}
如何获取图像
$sql = "SELECT * FROM upload WHERE uploadName = '%s'" ;
$result = $mysql->query(sprintf($sql,mysql_real_escape_string($name)));
var_dump($result->fetch_assoc())// Output Result
谢谢。