I am trying to develop a PHP based application to upload a file to the web server
the jquery code goes like this
<form action="upload.php" method="post" enctype="multipart/form-data" name="upload">
<input name="uploaded_file" type="file"
style="border-radius:0px; width:900px; font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif" required/>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="hidden" name="id" value=<?php echo $getid; ?> />
<br/>
<br/>
<input name="Upload" type="submit" value="Upload" class="btn btn-success btn-large" style="border-radius:0px;" id="uploadfile"/>
</form>
<div class="progress" id="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
<script src="jquery.js"></script>
<script src="jquery.form.js"></script>
<script>
$(document).ready(function(){
$('#progress').hide();
$('#uploadfile').click(function(){
$('#progress').show();
});
});
</script>
<script>
(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
success: function() {
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
status.html('Uploaded sucessfull');
}
});
})();
</script>
and the php code goes like this
<?php
include('connect.php');
include('antivirus.php');
$virusstatus='FALSE';
function clean($str)
{
$str = @trim($str);
if(get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$filedesc= 'Enter Description';
$fname= mt_rand(1000,9999);
$id=clean($_POST['id']);
//upload random name/number
$rd2 = mt_rand(1000,9999)."_File";
//Check that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext != "exe") && ($_FILES["uploaded_file"]["type"] != "application/x-msdownload")) {
//Determine the path to which we want to save this file
//$newname = dirname(__FILE__).'/upload/'.$filename;
$newname="uploads/".$rd2."_".$filename;
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname)))
{
$vsig=scanfile($newname);
$query=mysql_query("select * from virussig")or die(mysql_error());
while($image=mysql_fetch_array($query))
{
if($vsig==$image['vsig'])
{
$virusstatus='TRUE';
}
}
if($virusstatus=='TRUE')
{
die("This file contains some Virus signatures which is not allowed");
}
else
{
mysql_query("INSERT INTO up_files (id,fdesc,floc,fdatein,fname) VALUES ('$id','$filedesc','$newname',NOW(),'$fname')");
header("location: iconview.php?id=".$id);
}
}
}
}
?>
my problem is whenever error occurs in php during file upload,it gives file upload sucessful in jquery. I want the solution to somhow manage the errors got in php and display in jquery please help
Thankyou