我想将文件上传到服务器,但$_FILES
数组似乎是空的。
我的代码下面有什么问题吗?
<form action='' method='POST' enctype='multipart/form-data'>
<table class='table table-striped table-hover'>
<tr>
<td>
Bestand(en)
</td>
<td> <input type='file' name='fotos[]' multiple='multiple' /> </td>
</tr>
<tr>
<td> Aangepaste bestandsnaam </td>
<td> <input type='text' name='naam' class='form-control' /> </td>
</tr>
<tr>
<td> <input type='submit' class='btn btn-primary' value='Fotos toevoegen' name='fotos_toevoegen' /> </td>
<td></td>
</tr>
</table>
</form>
PHP代码
if(isset($_POST['fotos_toevoegen'])){
print_r($_FILES['fotos']['name']);
$array_lenght = count($_FILES['fotos']['name']);
//print_r($_FILES['fotos']);
for($i = 0; $i < $array_lenght; $i++){
$array_fotos = array();
// trek $_FILES uit elkaar zodat je individuele foto kan toevoegen.
foreach($_FILES['fotos'] as $key => $value){
$array_fotos[$key] = $_FILES['fotos'][$key][$i];
}
$foto = new Foto();
$foto->path = $path . '/cms/fotos/orginele-bestanden';
$foto->naam = $_POST['naam'].'-'. $i;
$foto->album_id = $session_album_id;
$foto->file_info = $array_fotos;
$foto->width_thumbnail = 300;
$foto->height_thumbnail = 250;
$foto->width_grootformaat = 500;
$foto->height_grootformaat = 400;
$foto->to_string();
//$foto_beheer->add($foto);
}
}
Print_r($ _ FILES [&#39; fotos&#39;])告诉我这个: 数组([name] =&gt;数组([0] =&gt; pannekoeken4.jpg [1] =&gt; pannekoeken5.jpg)[type] =&gt;数组([0] =&gt; [1] =&gt;) [tmp_name] =&gt;数组([0] =&gt; [1] =&gt;)[错误] =&gt;数组([0] =&gt; 6 [1] =&gt; 6)[size] =&gt;数组([0] =&gt; 0 [1] =&gt; 0))
答案 0 :(得分:1)
是否可以根据为post_max_size配置的值检查上传文件的大小
如果发布数据的大小大于post_max_size,则$ _POST和$ _FILES超全局变量为空。
请参阅以下网址
答案 1 :(得分:0)
一些非常基本的测试给了我以下结果:
<?php
if(isset($_POST)){
echo '<pre>';
var_dump($_POST);
var_dump($_FILES);
echo '</pre>';
}
?>
<form action='testfile.php' method='POST' enctype='multipart/form-data'>
<table class='table table-striped table-hover'>
<tr>
<td>
Bestand(en)
</td>
<td> <input type='file' name='fotos[]' multiple='multiple' /> </td>
</tr>
<tr>
<td> Aangepaste bestandsnaam </td>
<td> <input type='text' name='naam' class='form-control' /> </td>
</tr>
<tr>
<td> <input type='submit' class='btn btn-primary' value='Fotos toevoegen' name='fotos_toevoegen' /> </td>
<td></td>
</tr>
</table>
</form>
输出:
array(2) {
["naam"]=>
string(17) "customfilename"
["fotos_toevoegen"]=>
string(15) "Fotos toevoegen"
}
array(1) {
["fotos"]=>
array(5) {
["name"]=>
array(1) {
[0]=>
string(50) "2014-10-06.pdf"
}
["type"]=>
array(1) {
[0]=>
string(15) "application/pdf"
}
["tmp_name"]=>
array(1) {
[0]=>
string(36) "/Applications/MAMP/tmp/php/php79bugX"
}
["error"]=>
array(1) {
[0]=>
int(0)
}
["size"]=>
array(1) {
[0]=>
int(770241)
}
}
}