How to get rid of the undefined index below?
<p>I am getting an error stating that fileImage is an undefined index on this line: $idx = count($_POST ['fileImage']) -1 ;. Now this is happening because when user opens up the page, then obviously nothing is posted to fileImage, so how can I set it to "", when nothing is posted to the $_POST? I thought I did it in the line below but it doesn't seem that is happening.</p>

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

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

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

?&gt;
</code></pre>

<p>Javascript:</p>

<pre><code>function stopImageUpload(success) {

    var imageNameArray = ['&lt;?php echo $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;
}​
</code></pre>

<p>Below is the php script where it uploads a file which is on another page from the javascript function above:</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;


                    }
                }

            }

    $_POST ['fileImage'][] = array('name' =&gt; $_FILES ['fileImage']['name']);

            ?&gt;

        &lt;script language="javascript" type="text/javascript"&gt;window.top.stopImageUpload(&lt;?php echo $result;?&gt;);&lt;/script&gt;
</code></pre>
