Tell me how to upload a few pictures to the server and to the database. I didn’t get the code below, tell me how to fix the code so that you can upload some pictures. I load the file paths into the Base, the format is something like /i/ picture_name.jpg 1) In the database there are two fields id (int 10 A_U) and name (varchar 255). form code

<form id="form2" name="upload" action="exit.php" method="POST" ENCTYPE="multipart/form-data"> Выберите файл для загрузки: <input type="file" name="userfile[]" multiple accept="image/*" > <input type="submit" name="upload" value="Загрузить"> </form> 

derived array

 if(isset($_POST['upload'])) { ?><pre><?print_r ($_FILES['userfile']['name']);?></pre> <? } 

got this look

 Array ( [0] => nRLOalVq36k.jpg [1] => t1.jpg [2] => t2.jpg ) 

    1 answer 1

    You have multiple file uploads, as indicated by the multiple parameter in the input.

     if(($_FILES['userfile']['type'] == 'image/gif' || $_FILES['userfile']['type'] == 'image/jpeg' || $_FILES['userfile']['type'] == 'image/png') && ($_FILES['userfile']['size'] != 0 and $_FILES['userfile']['size']<=1024000)) 

    This condition does not pass the test, since all these elements are arrays of values, not values.

    Write

     var_dump($_FILES['userfile']['type']); 

    immediately after checking and understand what I'm talking about.

    You need to substitute the index of the file currently being processed (in your case, $k )

     if(($_FILES['userfile']['type']**[$k]** == 'image/gif' || //и так далее 

    and here

     $ex = explode('.',$_FILES['userfile']['name']**[$k]**); 

    and here

     if (move_uploaded_file($_FILES['userfile']['tmp_name']**[$k]**, //и так далее 


    I didn’t write long lines entirely so that it was better to see what we missed in the code