Image Upload Script


#1

Has any one can share image upload php code or jquery


#2

I found this

<?php
$Posted = array_merge($_GET, $_POST, $_FILES);
header("Content-type: application/json; charset=utf-8");
		if (strlen($Posted["upload"]["name"])>=4){
			$Posted["resimID"] = "78";
			$Posted["path"] = "storage/";
			$Posted["ek"] = "file_";
				$Posted["pFile"] = $Posted["upload"];
				$filename = uploadFile($Posted);
				list($width, $height) = getimagesize($Posted["path"]."".$filename);
				$kb = filesize($Posted["path"]."".$filename);
		}

upload Fonksyonu

function uploadFile($Posted){
	$abpath = $Posted["path"];
		$file = $Posted["pFile"]['tmp_name']; 
		$img_dat = explode(".",$Posted["pFile"]['name']);
		$uzanti = $img_dat[(sizeof($img_dat)-1)];
		$exFiles = array("JPG","jpg","gif","GIF","png","PNG","doc","docx","xls","xlsx","pdf");
		if (in_array($uzanti,$exFiles)) {
		$filename = $Posted["ek"]."f".$Posted["resimID"].".".$uzanti;
			if($a==copy($file, $abpath.$filename))
			{
				return $filename;
			}
		}
	return $filename;

}
?>

{“status_code”: 200, “status_txt”: “OK”,“data”: {“img_name”: “<?php echo $filename?>”,“img_url”: “http://xeditor.com/<?php echo $Posted["path"].$filename?>”,“img_view”: “http://xeditor.com/<?php echo $Posted["path"].$filename?>”, “img_width”: “<?php echo $width?>”,“img_height”: “<?php echo $height?>”,“img_attr”: “width=”<?php echo $width?>" height="<?php echo $height?>"",“img_size”: "<?php echo $kb/1024; ?> KB",“img_bytes”: <?php echo $kb/1024; ?> ,“source”: “base64 image string”,“resized”: “0”}}


#3

Thanks for your sharing!


"Cannot POST" error when sending Ajax