Please tell me there is a tag <input name="upload[]" type="file" multiple="multiple" /> How to make a php condition if input has a file. The issue has not been resolved. Somebody help ...

  • In theory, if($_FILES) - zhurof
  • @Gennadiy Zhurov for sure, thank you very much. - Vladislav Samokhin
  • @GennadiyZhurov Doesn’t work if there is no file in input - Vladislav Samokhin
  • Как сделать условие php если input имеет файл. And how should it be? - zhurof 5:58
  • Output $_FILES when the file is and when it is not and find the difference. - u_mulder 6:09

3 answers 3

Initially, a form must transfer not only field data, but also files.

 <form enctype="multipart/form-data" action="скрипт PHP" method="POST"> 

http://php.net/manual/ru/features.file-upload.post-method.php

  • And why did you think that my form is not like you wrote?) - Vladislav Samokhin
  • Well, you did not write it, and the error of the missing file can be caused during the transfer phase. You can check the availability of the file by the size or temporary file name. You can also check by transmission error code. just in the array you have error = 4. a 4 - The file was not loaded. php.net/manual/ru/features.file-upload.errors.php - Oleg Dmitrochenko

Initially, a form must transfer not only field data, but also files.

 <form enctype="multipart/form-data" action="скрин PHP" method="POST"> 

http://php.net/manual/ru/features.file-upload.post-method.php (well written here)

Then on the server to check the presence of the file.

 <?php if (isset($_FILES)) { foreach ($_FILES['upload']['tmp_name'] as $file) { echo '<li>' . $file . '</li>'; } } ?> 
  • This code does not work - Vladislav Samokhin

Solved the problem with this code:

 if (!empty($_FILES['upload']['name'][0])) { /* код */ } else { /* код 2 */ }