<form id="UploadForm" method="post" enctype="multipart/form-data"> <input type="file" id="upload" name="upload" > </form>
unction uploadimg(){ $.ajax({ url:"uploadImg.php", data:{}, success:function(response){ console.log(response); if(response=="success"){ alert("Image Uploaded Successfully"); } else if(response=="Invalid"){ alert("Invalid File Type"); } else{ alert("Image Not Uploaded"); } } }); }
$allowedExts = array("gif", "jpeg", "jpg", "png"); //$temp = explode(".", $_FILES["upload"]["name"]); //image //$extension = end($temp); echo $_FILES["upload"]["name"]; $ext=pathinfo($_FILES["upload"]["name"],PATHINFO_EXTENSION); echo "--------------------".$ext."-------------------------"; $src=""; if ((($_FILES["upload"]["type"] == "image/gif") || ($_FILES["upload"]["type"] == "image/jpeg") || ($_FILES["upload"]["type"] == "image/jpg") || ($_FILES["upload"]["type"] == "image/pjpeg") || ($_FILES["upload"]["type"] == "image/x-png") || ($_FILES["upload"]["type"] == "image/png")) && in_array($extension, $allowedExts)) { $filename = $_SESSION['username']. $_FILES['upload']['name']; move_uploaded_file($_FILES['upload']['tmp_name'],"upload/". $filename); //Update Query $query="update js_basic_details set image='".$filename."' where email_id='".$_SESSION['username']."'"; if(mysql_query($query)) return "success"; else return "Error"; } else{ echo "Invalid"; }
submit
action
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)