gpt4 book ai didi

php - 多文件上传PHP

转载 作者:行者123 更新时间:2023-12-04 05:10:14 24 4
gpt4 key购买 nike

我使用以下代码上传单个文件。使用此代码,我可以将单个文件上传到数据库。我想通过在单个 中选择多个文件来上传多个文件。输入类型文件 .我应该在代码中进行哪些更改以使其上传多个文件?

<?PHP
INCLUDE ("DB_Config.php");
$id=$_POST['id'];
$fileTypes = array('txt','doc','docx','ppt','pptx','pdf');
$fileParts = pathinfo($_FILES['uploaded_file']['name']);
if(in_array($fileParts['extension'],$fileTypes))
{
$filename = $_FILES["uploaded_file"]["name"];
$location = "E:\\test_TrainingMaterial/";
$file_size = $_FILES["uploaded_file"]["size"];
$path = $location . basename( $_FILES['uploaded_file']['name']);
if(file_exists($path))
{
echo "File Already Exists.<br/>";
echo "Please Rename and Try Again";
}
else
{
if($file_size < 209715200)
{
$move = move_uploaded_file( $_FILES["uploaded_file"]["tmp_name"], $location . $_FILES['uploaded_file']['name']);
$result = $mysqli->multi_query("call sp_upload_file('".$id."','" . $filename . "','".$path."')");
if ($result)
{
do {
if ($temp_resource = $mysqli->use_result())
{
while ($row = $temp_resource->fetch_array(MYSQLI_ASSOC)) {
array_push($rows, $row);
}
$temp_resource->free_result();
}
} while ($mysqli->next_result());
}
if($move)
{
echo "Successfully Uploaded";
}
else
{
echo "File not Moved";
}
}
else
{
echo "File Size Exceeded";
}
}
}
else
{
echo " Invalid File Type";
}
?>

使用的 Html 是
<form id = "upload_form" method="post" enctype="multipart/form-data"  >
<input type="file" name="uploaded_file" id="uploaded_file" style="color:black" /><br/>
</form>

最佳答案

基本上你需要添加到输入名称 [] 括号和属性“multiple”

<form id = "upload_form" method="post" enctype="multipart/form-data"  >
<input type="file" name="uploaded_file[]" multiple="true" id="uploaded_file" style="color:black" /><br/>
</form>

现在所有上传的文件都可以通过
$_FILES['uploaded_file']['name'][0]
$_FILES['uploaded_file']['name'][1]

等等

更多信息请访问
http://www.php.net/manual/en/features.file-upload.multiple.php

关于php - 多文件上传PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14975340/

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