0

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 ) )

5
  • Have you print like if(isset($_POST)){echo "<pre>";print_r($_FILES);echo "</pre>";} As your code looks proper Commented Nov 5, 2014 at 11:23
  • why action is empty? Commented Nov 5, 2014 at 11:23
  • Please, add your PHP code too. Commented Nov 5, 2014 at 11:24
  • @ Bhumi Shah Yes id did, I did print_r($_FILES) that's how I found out it was empty. Commented Nov 5, 2014 at 11:25
  • leaving action empty send you back to the same page ( I know it's not a good practise ) Commented Nov 5, 2014 at 11:25

2 Answers 2

1

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

Click here

Sign up to request clarification or add additional context in comments.

Comments

0

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)
    }
  }
}

3 Comments

Yes, but that's not what is happening on my server, could it be that it's not my code but some server setting?
Have you checked this post already? stackoverflow.com/questions/3586919/…
Ill check it out! If I find a solution, Ill post it here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.