post - PHP check if there is a file selected for upload -


I have this form and I would like to know if the user has chosen a file or not.

  & lt; Form action = "upload.php" method = "POST" encrypt = "multipart / form-data" & gt; & Lt; Select Name = "Category" & gt; & Lt; Option value = "cat 1" name = "cat 1" & gt; Product photos & lt; / Options & gt; & Lt; Option value = "cat 2" name = "cat 2" & gt; Portraitan & lt; / Options & gt; & Lt; Option value = "cat 3" name = "cat 3" & gt; Achattuur & lt; / Options & gt; & Lt; / Select & gt; & Lt; Input type = "file" name = "file_upload"> & Lt; Input type = "submit" name = "submit" value = "photo upload" & gt; & Lt; / Form & gt;  

I have written this PHP code to test it

  if (empty ($ _ POST) === incorrect) {$ fileupload = $ _POST [file_upload ']; If (empty ($ fileupload) === true) {// resonance "error no file selected"; } Other {print_r ($ _ files); }}  

But I got an error "no file was selected" even if I have picked some clue? I'm sorry I'm actually new to PHP

Edit :. I already tried the place $ fileupload = $ _FILES ['file_upload'] but this is an empty error (array print ([file_upload] => array ([name] => [type] => [tmp_name] => [ Error] => 4 [size] => 0))) When I do not enter a file?

"itemprop =" text ">

Use $ _ files array and UPLOAD_ERR_NO_FILE continuous:

  if (! Isset ($ _ FILES ['file_upload']) $ $ _FILES ['file_upload'] ['error'] == UPLOAD_ERR_NO_FILE) {resonance "error file not selected"; } Other {print_r ($ _ files); }  

You can also see UPLOAD_ERR_OK which indicates that the file was successfully uploaded (current and no errors).

Note: You can not use the empty_picker () on the $ _ files ['file_upload'] array, because even if No file has been uploaded, however it is still populated and the error element is set, which means empty () back false .


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -