我希望将正常的PHP文件上传更改为多文件上传。
我将此作为我的单个文件输入:
<input name="sliderfile" id="sliderfile" type="file" />
这是我用来上传到我的服务器/文件夹中的PHP并将其注册到我的数据库中:
if($_POST[sliderurl]){
$path= "uploads/".$HTTP_POST_FILES['sliderfile']['name'];
if($ufile !=none){
if(copy($HTTP_POST_FILES['sliderfile']['tmp_name'], $path)){
date_default_timezone_set('Europe/London');
$added = date("F j, Y");
$query = mysql_query("INSERT INTO `slider` (`imgurl`, `url`, `title`, `description`, `added`) VALUES ('$path', '$_POST[sliderurl]', '$_POST[slidertitle]', '$_POST[sliderdesc]', '$added')");
?>
<div id="fademessage" style="margin-top: 13px;">
<p class="message_greenadmin">Your slide has been successfully created and added to the homepage, Thank you.</p>
</div>
<?php
}else{
?>
<div id="fademessage" style="margin-top: 13px;">
<p class="message_redadmin">Something seems to have gone wrong. Try renaming the photos file name.</p>
</div>
<?php
}
}
}else{
}
?>
任何帮助将不胜感激,
谢谢!
答案 0 :(得分:0)
我认为这可能有用。使用括号(sliderfile [])为每个输入命名相同,然后循环它们。
foreach ($_FILES['sliderfile'] AS $file) {
UploadFile($file);
}
答案 1 :(得分:0)
您需要使用move_uploaded_file()来保存上传的文件。并且
foreach ($_FILES['sliderfile'] as $example) {
UploadFile($example);
}
答案 2 :(得分:0)
使用函数上传文件
function uploadImage($fileName,$filePath,$allowedList,$errorLocation){
$img = $_FILES[$fileName];
$imgName =$_FILES[$fileName]['name'];
$imgTempName = $_FILES[$fileName]['tmp_name'];
$imgSize = $_FILES[$fileName]['size'];
$imgError= $_FILES[$fileName]['error'];
$fileExt = explode(".",$imgName);
$fileActualExt = strtolower(end($fileExt));
$allowed = $allowedList;
if(in_array($fileActualExt, $allowed)){
if($imgError == 0){
foreach ($imgTempName as $example) {
$GLOBALS['fileNameNew']='yourname'.uniqid('',true).".".$fileActualExt;
$fileDestination = $filePath.$GLOBALS['fileNameNew'];
$resultsImage = move_uploaded_file($example,$fileDestination);
}
}
else{
header('location:'.$errorLocation.'&imgerror');
exit();
}
}
else{
header('location:'.$errorLocation.'&extensionError&'.$fileActualExt);
exit();
}
}