It is not appending the variable
<p>I want to append the name of the file which has been uploaded using the <code>$_POST</code> method to post the <code>$_FILES['fileImage']['name']</code> from the php script. Problem is that after the file has been uploaded, I don't see the filename appended, it just shows a blank. Why is it not appending the file's name after succesful upload of the file?</p>

<p>If anyone could provide a coded example then it would be very helpful.</p>

<p>Below is Javascript code:</p>

<pre><code>   &lt;?php
    session_start();

    $output = array();
    if(isset($_POST['fileImage'])){
        $idx = count($_POST['fileImage']) -1 ;
        $output[] = isset($_POST['fileImage'][$idx]) ?
            $_POST['fileImage'][$idx]['name'] : "";
    }

    ?&gt;

     &lt;script&gt;   


    function stopImageUpload(success) {
        var imageNameArray = &lt;?php echo  json_encode($output); ?&gt;;
        var result = '';

        if (success == 1) {
            result = '&lt;span class="msg"&gt;The file was uploaded successfully!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;';
            for (var i = 0; i &lt; imageNameArray.length; i++) {
                $('.listImage').append(imageNameArray[i] + '&lt;br/&gt;');
            }
        }
        else {
            result = '&lt;span class="emsg"&gt;There was an error during file upload!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;';
        }

        return true;
    }

&lt;/script&gt;
</code></pre>

<p>Below is the php script which uploads the  file and this script is on a seperate age from the Javascript function:</p>

<pre><code> &lt;?php
session_start();

$result = 0;
$errors = array ();
$dirImage = "ImageFiles/";

if (isset ( $_FILES ['fileImage'] ) &amp;&amp;
    $_FILES ["fileImage"] ["error"] == UPLOAD_ERR_OK) {

    $fileName = $_FILES ['fileImage'] ['name'];

    $fileExt = pathinfo ( $fileName, PATHINFO_EXTENSION );
    $fileExt = strtolower ( $fileExt );

    $fileDst = $dirImage . DIRECTORY_SEPARATOR . $fileName;

    if (count ( $errors ) == 0) {
        if (move_uploaded_file ( $fileTemp, $fileDst )) {
            $result = 1;
        }
    }
}

$_SESSION ['fileImage'][] = array('name' =&gt; $_FILES ['fileImage']['name']);
?&gt;
</code></pre>
