多个文件上载导致foreach()错误 [英] Multiple File Upload results in foreach() error
本文介绍了多个文件上载导致foreach()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ foreach $ _FILES ['pictures'] ['name'] as $ f = $ name $){
if($ _FILES ['pictures'] ['error'] [$ f] == 0){
$ name = $ date;
$ name。= - ;
$ name。= $ i;
$ name。=。;
$ extsearch = $ _FILES ['pictures'] ['name'] [$ f];
$ ext = pathinfo($ extsearch,PATHINFO_EXTENSION);
$ name。= $ ext;
if(move_uploaded_file($ _ FILES [pictures] [tmp_name] [$ f],$ path。$ name)){
if($ i == 1){
create_image_thumb($ albumFolder,$ name);
}
$ i ++;
resize_image($ albumFolder,$ name);
$ b然而,我收到这个错误在error_log中,文件不会被移动:
PHP警告:为/ home / clublabo中的foreach /public_html/management/create_album_action.php on line 43
更新:这里是HTML代码:
< form class =form form-horizontalaction =create_album_action.phpmethod =postenctype =multipart /表单数据>
< div class =form-group>
< label for =email-2class =col-sm-3 col-md-4 control-label>日期< / label>
< div class =col-sm-6 col-md-4>
< div class =input-with-icon>
< input name =dateAlbumclass =form-controltype =textvalue =<?php echo date('Y-m-d');?> data-provide =datepickerdata-date-autoclose =truedata-date-format =yyyy-mm-dd>< span class =icon icon-calendar input-icon><跨度>< / DIV>
< / div>
< / div>
< div class =form-group>
< label for =password-2class =col-sm-3 col-md-4 control-label>图片< / label>
< div class =col-sm-6 col-md-4>
< input name =picturesid =password-2class =form-controltype =filemultiple>
< / div>
< / div>
< div class =form-group>
< div class =col-sm-offset-3 col-sm-6 col-md-offset-4 col-md-4>
< button class =btn btn-primary pull-righttype =submit> Create Album< / button>
< / div>
< / div>
< / form>
也许你们有任何想法如何解决?
感谢:)
解决方案
替换:
< input name =picturesid =password-2class =form-controltype =filemultiple>
:
< input name =pictures []id =password-2class =form-controltype =filemultiple>
Actually trying to upload multiple pictures in a folder at once with some kind of renaming. The upload goes to the foreach loop. However, it does stop at this point:
foreach ($_FILES['pictures']['name'] as $f => $name) {
if ($_FILES['pictures']['error'][$f] == 0) {
$name = $date;
$name .= "-";
$name .= $i;
$name .= ".";
$extsearch = $_FILES['pictures']['name'][$f];
$ext = pathinfo($extsearch, PATHINFO_EXTENSION);
$name .= $ext;
if(move_uploaded_file($_FILES["pictures"]["tmp_name"][$f], $path.$name)) {
if ($i == 1) {
create_image_thumb($albumFolder, $name);
}
$i++;
resize_image($albumFolder, $name);
}
}
}
However, I receive this error in the error_log and the files aren't moved:
PHP Warning: Invalid argument supplied for foreach() in /home/clublabo/public_html/management/create_album_action.php on line 43
UPDATE: Here is the HTML Code:
<form class="form form-horizontal" action="create_album_action.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="email-2" class="col-sm-3 col-md-4 control-label">Date</label>
<div class="col-sm-6 col-md-4">
<div class="input-with-icon">
<input name="dateAlbum" class="form-control" type="text" value="<?php echo date('Y-m-d'); ?>" data-provide="datepicker" data-date-autoclose="true" data-date-format="yyyy-mm-dd"><span class="icon icon-calendar input-icon"></span></div>
</div>
</div>
<div class="form-group">
<label for="password-2" class="col-sm-3 col-md-4 control-label">Pictures</label>
<div class="col-sm-6 col-md-4">
<input name="pictures" id="password-2" class="form-control" type="file" multiple>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6 col-md-offset-4 col-md-4">
<button class="btn btn-primary pull-right" type="submit">Create Album</button>
</div>
</div>
</form>
Maybe you guys has any Idea how to have this resolved?
Thanks :)
解决方案
Replace:
<input name="pictures" id="password-2" class="form-control" type="file" multiple>
with:
<input name="pictures[]" id="password-2" class="form-control" type="file" multiple>
这篇关于多个文件上载导致foreach()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文