clv*_*vxc 13 php file-upload image image-uploading multiple-file-upload
我一直试图让这项工作相当长一段时间.但我似乎无法使其发挥作用.我想要一个只有一个输入的多图像上传表格.
这是我的upload.php
<?php
include("../include/session.php");
session_start();
$allowedExts = array("jpeg", "jpg", "png", "gif");
$extension = end(explode(".", $_FILES["upload"]["name"]));
if(isset($_FILES['upload']['tmp_name']))
{
for($i=0; $i < count($_FILES['upload']['tmp_name']);$i++)
{
if (($_FILES["upload"]["name"] < 90000000000000000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["upload"]["error"] > 0)
{
header('location: '.$error); die;
}
else
{
if (file_exists("../icons/".$_SESSION["username"] ."/" . $_FILES["upload"]["name"]))
{
echo "error";
}
else
{
if(!is_dir("../icons/". $_SESSION["username"] ."/")) {
mkdir("../icons/". $_SESSION["username"] ."/");
}
$temp = explode(".",$_FILES["upload"]["name"]);
$file = rand(1,999999999999) . '.' .end($temp);
move_uploaded_file($_FILES["upload"]["tmp_name"], "../icons/". $_SESSION["username"] ."/". $file);
}
}
}
} else {
echo "yep error";
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
如果我拿出线条
if(isset($_FILES['upload']['tmp_name']))
{
for($i=0; $i < count($_FILES['upload']['tmp_name']);$i++)
{
Run Code Online (Sandbox Code Playgroud)
使用相应的闭合支架,似乎工作正常.图像上传完美.但问题是,它只允许我上传一个.
请真的需要你的专业知识.谢谢
Kal*_*jai 41
好的链接:
使用ProgressBar和验证上传PHP/jQuery多个文件(点击此处下载源代码)
如何在PHP中上传文件并存储在MySql数据库中(点击此处下载源代码)
extract($_POST);
$error=array();
$extension=array("jpeg","jpg","png","gif");
foreach($_FILES["files"]["tmp_name"] as $key=>$tmp_name) {
$file_name=$_FILES["files"]["name"][$key];
$file_tmp=$_FILES["files"]["tmp_name"][$key];
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(in_array($ext,$extension)) {
if(!file_exists("photo_gallery/".$txtGalleryName."/".$file_name)) {
move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$file_name);
}
else {
$filename=basename($file_name,$ext);
$newFileName=$filename.time().".".$ext;
move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"photo_gallery/".$txtGalleryName."/".$newFileName);
}
}
else {
array_push($error,"$file_name, ");
}
}
Run Code Online (Sandbox Code Playgroud)
你必须检查你的HTML代码
<form action="create_photo_gallery.php" method="post" enctype="multipart/form-data">
<table width="100%">
<tr>
<td>Select Photo (one or multiple):</td>
<td><input type="file" name="files[]" multiple/></td>
</tr>
<tr>
<td colspan="2" align="center">Note: Supported image format: .jpeg, .jpg, .png, .gif</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Create Gallery" id="selectedButton"/></td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
好的链接:
使用ProgressBar和验证上传PHP/jQuery多个文件(点击此处下载源代码)
如何在PHP中上传文件并存储在MySql数据库中(点击此处下载源代码)