예제 #1
0
 public function Upload(Vtiger_Request $request)
 {
     $templateId = $request->get('template_id');
     $newName = basename($_FILES['watermark']['name'][0]);
     $newName = explode('.', $newName);
     $newName = $templateId . '.' . end($newName);
     $targetDir = Settings_PDF_Module_Model::$uploadPath;
     $targetFile = $targetDir . $newName;
     $uploadOk = 1;
     $imageFileType = pathinfo($targetFile, PATHINFO_EXTENSION);
     // Check if image file is a actual image or fake image
     $check = getimagesize($_FILES['watermark']['tmp_name'][0]);
     if ($check !== false) {
         // file is an image
         $uploadOk = 1;
     } else {
         // File is not an image
         $uploadOk = 0;
     }
     // Check allowed upload file size
     if ($_FILES['watermark']['size'][0] > vglobal('upload_maxsize') && $uploadOk) {
         $uploadOk = 0;
     }
     $saveFile = Vtiger_Functions::validateImage(['type' => $_FILES['watermark']['type'][0], 'tmp_name' => $_FILES['watermark']['tmp_name'][0], 'size' => $_FILES['watermark']['size'][0]]);
     if ($saveFile == 'false') {
         $uploadOk = 0;
     }
     // Check if $uploadOk is set to 0 by an error
     if ($uploadOk == 1) {
         $db = PearDatabase::getInstance();
         $query = 'SELECT `watermark_image` FROM `a_yf_pdf` WHERE `pdfid` = ? LIMIT 1;';
         $result = $db->pquery($query, [$templateId]);
         $watermarkImage = $db->getSingleValue($result);
         if (file_exists($watermarkImage)) {
             unlink($watermarkImage);
         }
         // successful upload
         if (move_uploaded_file($_FILES['watermark']['tmp_name'][0], $targetFile)) {
             $query = 'UPDATE `a_yf_pdf` SET `watermark_image` = ? WHERE `pdfid` = ? LIMIT 1;';
             $db = $db->pquery($query, [$targetFile, $templateId]);
         }
     }
 }
예제 #2
0
/**
 * 	This function is used to check whether the attached file is a image file or not
 * 	@param string $file_details  - vtiger_files array which contains all the uploaded file details
 * 	return string $save_image - true or false. if the image can be uploaded then true will return otherwise false.
 */
function validateImageFile($file_details)
{
    return Vtiger_Functions::validateImage($file_details);
}