tags:

views:

40

answers:

3

With a html type=file, how can I tell if file was uploaded. Is there something in the $_POST values to indicate so?

<form action="program" enctype="multipart/form-data" method="post">
<input type="text" name="textline" size="30">
<input type="file" name="datafile">
<input type="submit" value="Send">
</form>
+1  A: 

Check the $_FILES array:

if ($_FILES['datafile']['error'] == UPLOAD_ERR_OK) {
    // file was uploaded
}

'error' will match one of the predefined upload constants, see http://www.php.net/manual/en/features.file-upload.errors.php for all the possible values.

Tim Fountain
A: 
echo '<pre>';
var_dump($_FILES);
echo '</pre>';
Kieran Allen
A: 

The $_FILES variable contains information regarding file uploads, including original filename, mime type, temporary file name, error code and size of the uploaded file.

You