PHP:使用< input type ='file'>上传多张照片;同名 [英] PHP : Uploading multiple photos using <input type='file'> with same name

查看:165
本文介绍了PHP:使用< input type ='file'>上传多张照片;同名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用上传多张照片

I m trying to upload multiple photos using

<input type='file'>

与输入元素具有相同名称的

with same name to the input element like,

<?php
$remainGal  =   $maxGallery-$totalGallery;
if($remainGal>0){
?>
<div class="businessSPGItems">
<form name="addBusinessGallery" method="post" action="businessservices.php#messageGallery" enctype="multipart/form-data">
<input type="hidden" name="businessID" value="<?php echo $businessID;?>" />
<?php
for($i=0; $i<$remainGal; $i++){
?>
<input type="file" name="filePhotos[]" style="margin-top:5px;" tabindex="<?php echo $i+5; ?>" /><br />
<?php
}
?>
<input type="submit" name="btnAddGallery" value="Add" style="margin-top:10px;" tabindex="<?php echo $i+5; ?>" />
</form>
</div>
<?php
}
?>

但是问题是当我计算文件元素的总数时,它总是显示5 ... 即

But the problem is when i m taking the total count of the file element it always shows 5... ie.,

<?php 
$photos     =   $_FILES["filePhotos"];
echo count($photos);
?>

所以我一次不能上传超过5张照片. 我不知道我在做正确的方法. 请帮忙,, 谢谢...

So i could not upload more than 5 photos at a time.... i dont know i m doing the correct method.. help please,, thanks...

推荐答案

您的$_FILES["filePhotos"];将具有一个值数组.

Your $_FILES["filePhotos"]; will have an array of values.

阅读: http://php.net/manual/zh/features.file-upload.multiple.php

...数组$ _FILES ['userfile'],$ _ FILES ['userfile'] ['name'], 和$ _FILES ['userfile'] ['size']将被初始化... 这些中的每一个都是适当的数字索引数组 提交文件的值.

...the arrays $_FILES['userfile'], $_FILES['userfile']['name'], and $_FILES['userfile'] ['size'] will be initialized... Each of these will be a numerically indexed array of the appropriate values for the submitted files.

$_FILES["filePhotos"]["name"][0];
$_FILES["filePhotos"]["name"][1];
$_FILES["filePhotos"]["name"][2];
$_FILES["filePhotos"]["name"][3];
$_FILES["filePhotos"]["name"][4];

还请注意,有一个上传限制配置值. http://php.net/manual/zh/ini .core.php#ini.max-file-uploads

Also note that there is an upload limit config value. http://php.net/manual/en/ini.core.php#ini.max-file-uploads

允许同时上传的最大文件数. 从PHP 5.3.4开始,上传字段在提交时留为空白 计入此限制.

The maximum number of files allowed to be uploaded simultaneously. Starting with PHP 5.3.4, upload fields left blank on submission do not count towards this limit.

默认为20.

这篇关于PHP:使用&lt; input type ='file'&gt;上传多张照片;同名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆