Check if file exists in the upload file array

forms, php

Solution

`$_FILES[<key>]['tmp_name']` - contains file path on server

`$_FILES[<key>]['name']` - is just original file name

To address array of files `file[]` you need to fetch data by `$_FILES[<key>][<property>][<id>]`

try

if(!file_exists($_FILES['upload']['tmp_name'][0])) {

Manuals

http://www.php.net/manual/en/features.file-upload.php

http://www.php.net/manual/en/features.file-upload.multiple.php

Problem

I got form at frontend to submit stuff, wherein I need to check if file exists on submit. Please note that the form submits array of files. It is failing the all logics I have been trying. Please notice the `upload[]` on second line of html. HTML ``` <form method="post" id="upload-form" action="" enctype="multipart/form-data" > <input type="file" multiple="true" name="upload[]"> <input type="submit" name="upload_attachments" value="UPLOAD"> <form> ``` PHP ``` if(!file_exists($_FILES['upload']['tmp_name'].'/'.$FILES['upload']['name'])) { $upload_error = 'file is not set !'; return; //stop further code execution }else{ //do further validation } ``` The code above shows `'file is not set !'` in both cases, that is when I hit submit button without uploading a file and when I select to upload a file and hit the submit button. What is happening here, am I even doing it right? Basically I want to return a 'File Empty' message when someone hits the submit button without selecting a file to upload, and stop the further code execution.

Original source