Reputation: 573
I want to upload a file to the server but the $_FILES
array seems to empty.
Is there something wrong with my code below ?
<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 CODE
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['fotos']) shows me this: Array ( [name] => Array ( [0] => pannekoeken4.jpg [1] => pannekoeken5.jpg ) [type] => Array ( [0] => [1] => ) [tmp_name] => Array ( [0] => [1] => ) [error] => Array ( [0] => 6 [1] => 6 ) [size] => Array ( [0] => 0 [1] => 0 ) )
Upvotes: 0
Views: 4991
Reputation: 61
Can you please check the size of the file uploaded against value configured for post_max_size
If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty.
Please refer the following URL
Upvotes: 1
Reputation: 1101
Some very basic testing gave me the following result:
<?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>
Output:
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)
}
}
}
Upvotes: 0