It's fine working when I request from postman but when using android request not working "imagejpeg($new_canvas, $destination_folder.'/'.$image_name , 90)" means photo are not upload to server folder ,rest all are working fine
Android Code:
class LoadAlllist extends AsyncTask<String, String, String>
{
ProgressDialog pDialog;
@Override
protected void onPreExecute()
{
super.onPreExecute();
pDialog = new ProgressDialog(AllPhoto.this);
pDialog.setMessage("Loading Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args)
{
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("imagepath", uploadimagepath));
params.add(new BasicNameValuePair("profileid", docid));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest("http://example.in/updateDocImage.php",
"POST", params);
try
{
status =json.getString("status");
msg=json.getString("message");
}
catch (Exception e)
{
// TODO: handle exception
}
return null;
}
Php code:
<?php
require_once('../classes/clinic.php');
error_reporting(E_ALL);
ini_set("display_errors", 1);
$res= array();
$res1= array();
$profileid=$_REQUEST['profileid'];
$imagepath=$_REQUEST['imagepath'];
$max_size = 8000; //max image size in Pixels
$destination_folder = $_SERVER['DOCUMENT_ROOT'].'/'.'img/profile_thumbnail';
$watermark_png_file = 'http://doctorstay.in/img/php/watermark.png'; //watermark png file
$imageURL = $imagepath;
$url_arr = explode ('/', $imageURL);
$ct = count($url_arr);
$name = $url_arr[$ct-1];
$name_div = explode('.', $name);
$image_name= $name;
$typeInt = exif_imagetype($imageURL);
switch($typeInt) {
case IMAGETYPE_GIF:
$image_resource = imagecreatefromgif($imageURL);
break;
case IMAGETYPE_JPEG:
$image_resource = imagecreatefromjpeg($imageURL);
break;
case IMAGETYPE_JPEG:
$image_resource = imagecreatefromjpeg($imageURL);
break;
case IMAGETYPE_PNG:
$image_resource = imagecreatefrompng($imageURL);
break;
default:
$image_resource = false;
}
if($image_resource)
{
//Copy and resize part of an image with resampling
list($img_width, $img_height) = getimagesize($imageURL);
//Construct a proportional size of new image
$image_scale = min($max_size / $img_width, $max_size / $img_height);
/* $new_image_width = ceil($image_scale * $img_width/2);
$new_image_height = ceil($image_scale * $img_height/2);*/
$new_image_width = 400;
$new_image_height = 268;
$new_canvas = imagecreatetruecolor($new_image_width , $new_image_height);
if(imagecopyresampled($new_canvas, $image_resource , 0, 0, 0, 0, $new_image_width, $new_image_height, $img_width, $img_height))
{
if(!is_dir($destination_folder)){
mkdir($destination_folder);//create dir if it doesn't exist
}
//center watermark
$watermark_left = ($new_image_width/2)-(300/2); //watermark left
$watermark_bottom = ($new_image_height/2)-(100/2); //watermark bottom
$watermark = imagecreatefrompng($watermark_png_file); //watermark image
imagecopy($new_canvas, $watermark, $watermark_left, $watermark_bottom, 0, 0, 300, 100); //merge image
if(imagejpeg($new_canvas, $destination_folder.'/'.$image_name , 90)) {
// echo "success";
} else{
// echo "fail";
}
imagedestroy($new_canvas);
imagedestroy($image_resource);
//die();
}
}
$result=clinic::updateDocImage($imagepath,$profileid);
if( isset($result))
{
$res["status"]="success";
$res["message"]="";
}
else
{
$res["status"]="failed";
$res["message"]="No record inserted.";
}
echo json_encode($res);
?>