-1

I am trying to display the name of the uploaded file below the input button. The default text should say "No File Uploaded", once the file is selected and added to the server "file_name.ext was uploaded".

Here is my code at the moment:

<label for='upload' class='upload-button'></label><input type='file' name="fileAttach" class='upload-button' id='upload'/><br>Upload Site List
<?php
if (isset($_FILES['fileAttach']['name'])) {
    echo "File is attached.";
}
?>

This code is on the form page using POST with enctype multipart/form-data.

My knowledge is below the entry level, so I'm sorry if this is really simple question. All the info I found so far did not help.

1
  • 1
    Well, if you manage to find $_FILES['fileAttach']['name'] and the echo command it shouldn't be too hard to write echo $_FILES['fileAttach']['name']; Commented Oct 9, 2014 at 13:42

2 Answers 2

0
<label for='upload' class='upload-button'></label><input type='file' name="fileAttach" class='upload-button' id='upload'/><br>Upload Site List
    <?php
    if(isset($_FILES['fileAttach']['name'])) {
        echo $_FILES['fileAttach']['name']." was uploaded";
    }else{
        echo "No File Uploaded";
    }
    ?>
1
  • None of the messages gets echoed. Will the isset function work in a form using POST before it is submitted? Commented Oct 9, 2014 at 14:02
0

The form will have to be submitted for php to echo the statement.

<form enctype="multipart/form-data" action="" method="POST">
<input type='file' name="fileAttach" class='upload-button' id='upload'/>
<input type="submit">
</form>

<br>Upload Site List<br>
<?php
    if(isset($_FILES['fileAttach']['name'])) {
        echo $_FILES['fileAttach']['name'] . " was uploaded";
    } else {
        echo "No File Uploaded";
    }
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.