gpt4 book ai didi

php - 保存多个附件并检索它们

转载 作者:行者123 更新时间:2023-12-02 19:42:58 25 4
gpt4 key购买 nike

我有一个简单的 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 页面上检索这些文件。请,我是初学者,所以有教程。

最佳答案

这个问题已经在这里回答过多次了..请参阅

multi image upload wrong quantity on file-upload

limiting the checking condition while uploading swf files

编辑 1

我认为你的 table 应该是什么样的

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

谢谢。

关于php - 保存多个附件并检索它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10171751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com