用PHP上传HTML 5多文件 [英] HTML 5 multi file upload with PHP
问题描述
这是我的代码,我想知道我做错了它没有显示名称。
< form action =self.phpmethod =postenctype =multipart / form-data>
< input type =filename =imageURL []id =imageURLmultiple =/>
< input type =submitvalue =submitname =submit/>
< / form>
处理信息不起作用:
foreach($ _FILES ['imageURL'] as $ files []){
echo $ files ['file'];
编辑:
将我的foreach循环更改为:
foreach($ _FILES ['imageURL'] as $文件){
echo $ file ['name'];
}
仍然没有打印出来。
然而,当我做这样的事情时:
foreach($ _FILES ['imageURL'] ['name' ] as $ filename){
echo $ filename;
}
文件名不会打印。我不知道这意味着什么。
已解决更新:
由John Conde链接,上传多个文件时的阵列交错结构与上传单个文件时不同。要使用foreach,我们必须重组数组。
$ files = array();
$ fdata = $ _ FILES ['imageURL'];
if(is_array($ fdata ['name'])){
for($ i = 0; $ i< count($ fdata ['name']); ++ $ i){
$ files [] = array(
'name'=> $ fdata ['name'] [$ i],
'type'=> $ fdata ['type'] [ $ i],
'tmp_name'=> $ fdata ['tmp_name'] [$ i],
'error'=> $ fdata ['error'] [$ i],
'size'=> $ fdata ['size'] [$ i]
);
}
} else $ files [] = $ fdata;
现在我们可以使用foreach循环:
foreach($ files as $ file){
echo $ file ['name'];
}
试用
foreach($ _FILES ['imageURL'] as $ file){
echo $ file ['name'];
}
更新:
Google发现本教程 a>可能会帮助你 Here is the code I have, and I'm wondering what I'm doing wrong that it doesn't display the name. And the processing info that isn't working: Edit: When changing my foreach loop to: Still nothing prints out. However, when I do something like this: The filename does print. I don't know what that implies though. As linked to by John Conde, the array interlace structure is different when uploading multiple files than when uploading a single file. To use foreach, we must restructure the array. NOW we can use foreach to loop:
Try UPDATE: Google found this tutorial which may help you 这篇关于用PHP上传HTML 5多文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<form action = "self.php" method="post" enctype="multipart/form-data">
<input type="file" name="imageURL[]" id="imageURL" multiple="" />
<input type="submit" value="submit" name="submit" />
</form>
foreach ($_FILES['imageURL'] as $files[]) {
echo $files['file'];
}
foreach ($_FILES['imageURL'] as $file) {
echo $file['name'];
}
foreach ($_FILES['imageURL']['name'] as $filename) {
echo $filename;
}
SOLVED UPDATE:$files=array();
$fdata=$_FILES['imageURL'];
if(is_array($fdata['name'])){
for($i=0;$i<count($fdata['name']);++$i){
$files[]=array(
'name' =>$fdata['name'][$i],
'type' => $fdata['type'][$i],
'tmp_name'=>$fdata['tmp_name'][$i],
'error' => $fdata['error'][$i],
'size' => $fdata['size'][$i]
);
}
}else $files[]=$fdata;
foreach ($files as $file) {
echo $file['name'];
}
foreach ($_FILES['imageURL'] as $file) {
echo $file['name'];
}