Exemple #1
0
 function imageUpload($argFILES, $argVarDirLocation, $varThumbnailWidth = '', $varThumbnailHeight = '', $varMediumWidth = '', $varMediumHeight = '')
 {
     $objUpload = new upload();
     $objCore = new Core();
     $objUpload->setMaxSize();
     $objUpload->setDirectory($argVarDirLocation);
     $varIsImage = $objUpload->IsImageValid($argFILES['type']);
     if ($varIsImage) {
         $varImageExists = 'yes';
     } else {
         $varImageExists = 'no';
     }
     if ($varImageExists == 'no') {
         $objCore->setErrorMsg(IMAGE_TYPE_ERROR);
         return false;
     }
     if ($varImageExists == 'yes') {
         $objUpload->setTmpName($argFILES['tmp_name']);
         if ($objUpload->userTmpName) {
             $objUpload->setFileSize($argFILES['size']);
             $objUpload->setFileType($argFILES['type']);
             $varRandomNumber = $this->generateRandomKey();
             $fileName = $varRandomNumber . '_' . strtolower($argFILES['name']);
             $fileName = str_replace(' ', '_', $fileName);
             $objUpload->setFileName($fileName);
             $objUpload->startCopy();
             if ($objUpload->isError()) {
                 $thumbnailName1 = '_thumb';
                 $objUpload->setThumbnailName($thumbnailName1);
                 $objUpload->createThumbnail();
                 if ($varThumbnailWidth == '' && $varThumbnailHeight == '') {
                     $objUpload->setThumbnailSize();
                 } else {
                     $objUpload->setThumbnailSize($varThumbnailWidth, $varThumbnailHeight);
                 }
                 $varFileName = $objUpload->userFileName;
                 $varExt = substr(strrchr($varFileName, "."), 1);
                 $varThumbFileNameNoExt = substr($varFileName, 0, -(strlen($varExt) + 1));
                 $varThumbFileName = $varThumbFileNameNoExt . 'thumb.' . $varExt;
                 $thumbnailName1 = '';
                 $objUpload->setThumbnailName($thumbnailName1);
                 $objUpload->createThumbnail();
                 if ($varMediumWidth == '' && $varMediumHeight == '') {
                     $objUpload->setThumbnailSize();
                 } else {
                     $objUpload->setThumbnailSize($varMediumWidth, $varMediumHeight);
                 }
                 return $varFileName;
             } else {
                 $objCore->setErrorMsg(ERROR_ON_UPLOAD);
                 return false;
             }
         }
     }
 }
Exemple #2
0
 function imageUpload($argFILES, $argVarDirLocation, $varThumbnailWidth = '', $varThumbnailHeight = '', $varMediumWidth = '', $varMediumHeight = '')
 {
     //$argVarProductName = $argFILES['name'];
     $objUpload = new upload();
     $objCore = new Core();
     $objUpload->setMaxSize();
     // Set Directory
     $objUpload->setDirectory($argVarDirLocation);
     $varIsImage = $objUpload->IsImageValid($argFILES['type']);
     if ($varIsImage) {
         $varImageExists = 'yes';
     } else {
         $varImageExists = 'no';
     }
     if ($varImageExists == 'no') {
         $objCore->setErrorMsg(IMAGE_TYPE_ERROR);
         return false;
     }
     if ($varImageExists == 'yes') {
         $objUpload->setTmpName($argFILES['tmp_name']);
         //echo $objUpload->userTmpName;die;
         if ($objUpload->userTmpName) {
             // Set file size
             $objUpload->setFileSize($argFILES['size']);
             // Set File Type
             $objUpload->setFileType($argFILES['type']);
             // Set File Name
             $varRandomNumber = $this->generateRandomKey();
             $fileName = $varRandomNumber . '_' . strtolower($argFILES['name']);
             //replace space with an underscore
             $fileName = str_replace(' ', '_', $fileName);
             $objUpload->setFileName($fileName);
             // Start Copy Process
             $objUpload->startCopy();
             // If there is error write the error message
             if ($objUpload->isError()) {
                 // Set a thumbnail name
                 $thumbnailName1 = '_thumb';
                 $objUpload->setThumbnailName($thumbnailName1);
                 // create thumbnail
                 $objUpload->createThumbnail();
                 // change thumbnail size
                 if ($varThumbnailWidth == '' && $varThumbnailHeight == '') {
                     $objUpload->setThumbnailSize();
                 } else {
                     $objUpload->setThumbnailSize($varThumbnailWidth, $varThumbnailHeight);
                 }
                 //Get file name from the class public variable
                 $varFileName = $objUpload->userFileName;
                 //Get file extention
                 $varExt = substr(strrchr($varFileName, "."), 1);
                 $varThumbFileNameNoExt = substr($varFileName, 0, -(strlen($varExt) + 1));
                 //Create thumb file name
                 $varThumbFileName = $varThumbFileNameNoExt . 'thumb.' . $varExt;
                 //--------------------FOR MEDIUM SIZE IMAGE--------------------------
                 // Set a MIDIUM name
                 $thumbnailName1 = '';
                 $objUpload->setThumbnailName($thumbnailName1);
                 // create thumbnail
                 $objUpload->createThumbnail();
                 // change thumbnail size
                 //$objUpload->setThumbnailSize(169, 198);
                 if ($varMediumWidth == '' && $varMediumHeight == '') {
                     $objUpload->setThumbnailSize();
                 } else {
                     $objUpload->setThumbnailSize($varMediumWidth, $varMediumHeight);
                 }
                 //Add  fields in pictures table
                 return $varFileName;
             } else {
                 $objCore->setErrorMsg(ERROR_ON_UPLOAD);
                 return false;
             }
         }
     }
 }