public function imageupload() { $savefolder = USER_PREVIEW_UPLOAD_PATH; // folder for upload $max_size = 1024; // maxim size for image file, in KiloBytes // Allowed image types //$allowtype = array('gif', 'jpg', 'jpeg', 'png'); $allowtype = array('gif', 'jpg', 'jpeg', 'png', 'GIF', 'JPG', 'JPEG', 'PNG'); /** Uploading the image **/ $rezultat = ''; $result_status = ''; $result_msg = ''; // if is received a valid file if (isset($_FILES['profile_photo'])) { $type = explode(".", strtolower($_FILES['profile_photo']['name'])); //echo in_array($type, $allowtype);exit; if (in_array($type[1], $allowtype)) { // check its size if ($_FILES['profile_photo']['size'] != 0 && $_FILES['profile_photo']['size'] <= $max_size * 1024) { // if no errors if ($_FILES['profile_photo']['error'] == 0) { //$newname = 'preview_'.date("His").'.'.$type[1]; $newname = 'organisation_image_' . time() . '.' . $type[1]; $thefile = $savefolder . "/" . $_FILES['profile_photo']['name']; $newfilename = $savefolder . "/" . $newname; $filename = $newname; if (!move_uploaded_file($_FILES['profile_photo']['tmp_name'], $newfilename)) { $rezultat = ''; $result_status = 'error'; $result_msg = 'The file cannot be uploaded, try again.'; } else { $rezultat = $filename; $setWidth = 265; $setHeight = 40; list($imgwidth, $imgheight) = getimagesize($newfilename); if ($imgwidth < 265) { $setWidth = $imgwidth; } if ($imgheight < 40) { $setHeight = $imgheight; } if ($imgwidth > 265 || $imgheight > 40) { sapp_Global::smartresizeimage($newfilename, $setWidth, $setHeight, false, 'file', false, false); } $result_status = 'success'; $result_msg = ''; } } } else { $rezultat = ''; $result_status = 'error'; $result_msg = 'Image size must not exceed ' . $max_size . ' KB.'; } } else { $rezultat = ''; $result_status = 'error'; $result_msg = 'Please upload only .gif, .jpg, .jpeg, .png images.'; } } else { $rezultat = ''; $result_status = 'error'; $result_msg = 'Please upload only .gif, .jpg, .jpeg, .png images.'; } $result = array('result' => $result_status, 'img' => $rezultat, 'msg' => $result_msg); return $result; }