How to tweak this code for alert box and confirmation box to appear when uploading files
<p>I have an application <a href="http://helios.hud.ac.uk/u0867587/Files/Files.php" rel="nofollow">here</a> where the code for the application is below:</p>

<pre><code>&lt;script type="text/javascript"&gt;


var qnum = 1;

function insertQuestion(form) {   


    var $tbody = $('#qandatbl &gt; tbody'); 
    var $tr = $("&lt;tr class='optionAndAnswer' align='center'&gt;&lt;/tr&gt;");
    var $qid = $("&lt;td class='qid'&gt;" + qnum + "&lt;/td&gt;");
    var $image = $("&lt;td class='image'&gt;&lt;/td&gt;");


            var $imagefile = $('&lt;input /&gt;')
        .attr({
            type: 'file',
            name: 'imageFile',
            class: 'imageFile'
        });

        $image.append($imagefile);

            var $imageclear = $('&lt;input /&gt;')
        .attr({
            type: 'button',
            name: 'imageClear',
            class: 'imageClear',
            value: 'Clear File'
        });

        $image.append($imageclear);


    $tr.append($qid);
    $tr.append($image);   
    $tbody.append($tr); 

}


function validation() {


    var alertValidation = "";
    // Note, this is just so it's declared...


    if (alertValidation != "") {
        alert(_alertValidation);
        return false;
    }

    return true;
}

             function showConfirm(){

         var confirmMsg=confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Session." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" );

         if (confirmMsg==true)
         {
         submitform();   
     }
}

            function submitform()
            {

        var sessionMarksO = document.getElementById("sessionMarks");

          sessionMarksO.submit();

            }


&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;form id="enter" action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post" onsubmit="return validateForm(this);" &gt;
&lt;div id="detailsBlock"&gt;


&lt;table id="questionBtn" align="center"&gt;
&lt;tr&gt;
&lt;th&gt;
&lt;input id="addQuestionBtn" name="addQuestion" type="button" value="Add Question" onClick="insertQuestion(this.form)" /&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;/div&gt;
&lt;hr/&gt;

&lt;div id="details"&gt;
&lt;table id="qandatbl" align="center"&gt;
&lt;thead&gt;
&lt;tr&gt;
    &lt;th class="qid"&gt;Question No&lt;/th&gt;
    &lt;th class="image"&gt;Image&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;

&lt;/form&gt; 


&lt;form action="session_marks.php" method="post" id="sessionMarks"&gt;

&lt;p&gt;&lt;input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="myClickHandler(); return false;" /&gt;&lt;/p&gt;

&lt;/form&gt;

         &lt;script type="text/javascript"&gt;

function myClickHandler(){
     if(validation()){
                showConfirm();
     }
}

&lt;/script&gt;



&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>In the application you click on the "Add Question" button and a new table row is added. Now select a file and click on submit, the confirmation box appears.</p>

<p>Now what I want to do is this below:</p>

<p>I want to include this code below in the application which checks for file formats and file restrictions through server side:</p>

<pre><code>&lt;?php
    if(isset($_POST["submit"])){
        $allowedtypes=array("jpg"=&gt;true,"png"=&gt;true,"gif"=&gt;true,"txt"=&gt;true);
        $filename = $_FILES['imageFile']['name'];  
        $source = $_FILES['imageFile']['tmp_name'];  
        $file_size=$_FILES['imageFile']['size'];
        $saveloc = "uploads/" . $filename;
        $maxfilesize=1024*1024*10;
        $nameext=explode(".",$filename);
        if(preg_match('/^[A-Za-z0-9\-\_]{1,}\.[a-zA-Z0-9]{0,4}$/',$filename)){
            if(!empty($allowedtypes[strtolower($nameext[1])]) &amp;&amp; $allowedtypes[strtolower($nameext[1])]===true){
                if($file_size&lt;=$maxfilesize){
                    if(!file_exists($saveloc)){
                        if(move_uploaded_file($source, $saveloc)) { 
                            chmod($saveloc,644);
                            echo "Successful upload. &lt;a href='".$saveloc."'&gt;Fájl megtekintése&lt;/a&gt;";
                        }
                        else echo "&lt;scirpt type='text/javascript'&gt;alert('Cannot move');&lt;/script&gt;";
                    }
                    else echo "&lt;scirpt type='text/javascript'&gt;alert('Existing file');&lt;/script&gt;";
                }
                else echo "&lt;scirpt type='text/javascript'&gt;alert('Too big File');&lt;/script&gt;";

            }
            else echo "&lt;scirpt type='text/javascript'&gt;alert('Not allowed extension');&lt;/script&gt;";
        }
        else echo "&lt;scirpt type='text/javascript'&gt;alert('Only alphanumeric files allowed');&lt;/script&gt;";

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

<p>What I want to know is how can I tweak the code so that if the file is invalid, it displays an alert through the validation() function and if the file is valid, then it should show the confirmation message it is currently showing through the myClickHandler() function?</p>

<p>Thanks</p>
