HTML:
<form id="myForm" style="display:none" action='picture.php' method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file"/><br/>
<input type="submit" id="submit"/><br/>
</form>
Script:
$('#templatemo_content_wrapper').on('click', '#change',function(){
$("#file").trigger('click');
});
$('#file').change(function(){
$("#submit").trigger('click');
});
$('#myForm').ajaxForm({
beforeSend : function(){
$('#change').fadeOut(1);
},
UploadProgress : function(){},
success : function(){},
complete : function(){
var split = location.search.replace('?', '').split('=')
var id = split[1];
$.post('profile_processor.php',{id:id},function(data){
$('#templatemo_content_wrapper').html(data);
checked('rel');
checked('gpa');
checked('student');
});
$('#upload_pic').fadeOut(1);
$('#change').fadeIn(1);
}
});
PHP:
if(isset($_FILES['file'])===true){
if(!empty($name=$_FILES['file']['name'])){
$allowed=array('jpg','jpeg','gif','png');
$file_name=$_FILES['file']['name'];
$file_ext=strtolower(end(explode('.',$file_name)));
$file_temp=$_FILES['file']['tmp_name'];
if(in_array($file_ext,$allowed)===true){
cheange_profile_picture($session_user_id,$file_temp,$file_ext);
mysql_query("UPDATE `users` SET `img_active`=1 where `id`=$session_user_id");
}
}
}
When I uploaded my file on Godaddy host, none of the AJAX calls work except one of them. AJAX call doesn't send the data into PHP script. To make it more clear if I add die();
in the PHP at the very begging of the page, it wont affect the code at all. However if I add an alert()
into AJAX success
callback, it show the alert. I really don't know how to come up with a solution.
Any help will be very appreciated.