<?php
    
if (isset($_FILES['myfile'])) :
        
$destination_path "./";
        
$result 0;
        
$target_path $destination_path basename$_FILES['myfile']['name']);
        if(@
move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
            
$result 1;
        }
        
sleep(1); // Simulate that it takes a while, users tend to be sceptic if uploading happens too quick.
?>
<script language="javascript" type="text/javascript">
    window.top.window.stopUpload(<?php echo $result?>);
</script>     
<?php
    
die();
    endif;
?>
<style type="text/css">
#f1_upload_process{
    z-index:100;
    position:absolute;
    visibility:hidden;
    text-align:center;
    width:400px;
    margin:0px;
    padding:0px;
    background-color:#fff;
    border:1px solid #ccc;
}
 
form[target='upload_target']{
    text-align:center;
    width:390px;
    margin:0px;
    padding:5px;
    background-color:#fff;
    border:1px solid #ccc;
}
</style>
<h1>Upload</h1>
<p id="f1_upload_process">Loading...<br/></p>
<p id="result"></p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >
    File: <input name="myfile" type="file" />
    <input type="submit" name="submitBtn" value="Upload" />
</form>
<iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe> 

<script type="text/javascript">
    function startUpload(){
        document.getElementById('f1_upload_process').style.visibility = 'visible';
        return true;
    }
    function stopUpload(success){
        var result = '';
        if (success == 1){
            document.getElementById('result').innerHTML =
            '<div class="msg">The file was uploaded successfully!</div>';
        } else {
            document.getElementById('result').innerHTML =
            '<div id="error">There was an error during file upload!</div>';
        }
        document.getElementById('f1_upload_process').style.visibility = 'hidden';
        return true;
    }
</script>