Friday, February 14, 2014

compress image during upload

function compress_image($source_url, $destination_url, $quality) { $info = getimagesize($source_url); if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source_url); elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source_url); elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source_url); imagejpeg($image, $destination_url, $quality); return $destination_url; } if(isset($_FILES['add_image1'])){ $tt=time(); $target_path = "../product_image/".$tt; $target_path = $target_path . basename( $_FILES["add_image1"]['name']); $pn="product_image/".basename( $_FILES["add_image1"]['name']); $ch=strtolower(substr($pn, strrpos($pn,".")+1)); if($ch=="jpg" or $ch=="png" or $ch=="jpeg" or $ch=="gif"){ if(move_uploaded_file($_FILES['add_image1']['tmp_name'], $target_path)) { mysqli_query($db_con,"update table_question set image='".$target_path."' where question_id=".$pro_id); $destination=$target_path; $t=compress_image($target_path,$destination, 50); if($t!=''){ mysqli_query($db_con,"update table_question set image='".$filename."' where question_id=".$pro_id); } } } }

resize image during upload

if(isset($_FILES['add_image1'])){ $tt=time(); $target_path = "../product_image/".$tt; $target_path = $target_path . basename( $_FILES["add_image1"]['name']); $pn="product_image/".basename( $_FILES["add_image1"]['name']); $ch=strtolower(substr($pn, strrpos($pn,".")+1)); if($ch=="jpg" or $ch=="png" or $ch=="jpeg" or $ch=="gif"){ $uploadedfile = $_FILES['add_image1']['tmp_name']; //$size=filesize($_FILES['add_image1']['tmp_name']); if (!empty($uploadedfile)){ $info = getimagesize($uploadedfile); if($ch=="jpg" || $ch=="jpeg" ) { if ($info['mime'] == 'image/jpeg') $src = imagecreatefromjpeg($uploadedfile); } else if($ch=="png") { if($info['mime'] == 'image/png') $src = imagecreatefrompng($uploadedfile); } else { if($info['mime'] == 'image/gif') $src = imagecreatefromgif($uploadedfile); } list($width,$height)=getimagesize($uploadedfile); $newwidth=100; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); if(!empty($src)){ imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); $filename = "../product_image/".$tt. $_FILES['add_image1']['name']; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); mysqli_query($db_con,"update table_question set image='".$filename."' where question_id=".$pro_id); } } } }

ajax opens php file

function showTYPE(str) { var xmlhttp1, str; if (str.length==0) { showtype.innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp1=new XMLHttpRequest(); //alert("hi"); } else {// code for IE6, IE5 xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp1.open("GET","type.php?q="+str,true); xmlhttp1.send(); xmlhttp1.onreadystatechange=function() { //document.write(xmlhttp1.responseText); showtype.innerHTML=xmlhttp1.responseText; } }

Access to Folder in C and D Drive

Drive D 1. D: / 2. cd "D:\foldername" Drive C 1. cd\ 2. cd foldername/foldername