Beispiel #1
0
 /**
  * Menyimpan file ke direktori
  * @param string $destination folder tujuan disarankan menggunakan ResourcesPath()
  * @param string $fileName    nama file (optional)
  */
 public static function save($destination, $fileName = '')
 {
     $extension = self::getExtension();
     if (!empty($fileName)) {
         self::$name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $fileName) . "." . $extension;
     }
     if (file_exists(removeMultiple($destination . "/" . self::$name)) && self::$overwrite == FALSE) {
         //echo RemoveMultiple($destination . "/" . self::$Name);
         trigger_error("File already exist, to overwrite file set you can use \\UploadedFile::Overwrite(TRUE)", E_USER_ERROR);
     }
     if (self::$removeSpaces) {
         self::$name = str_replace(" ", "", self::$name);
     }
     // Jika nama file di encrypt
     if (self::$encryptName) {
         self::$name = md5(date("Y-m-d G:i:s" . Config::Get('App', 'AppKey')) . self::$name) . "." . $extension;
     }
     if (in_array($extension, self::$imageExtension)) {
         //move_uploaded_file(self::$File['tmp_name'], RemoveMultiple($destination . "/" . self::$Name));
         switch (strtolower($extension)) {
             case 'jpg':
             case 'jpeg':
                 $img = imagecreatefromjpeg(self::$file['tmp_name']);
                 imagejpeg($img, removeMultiple($destination . "/" . self::$name));
                 break;
             case 'png':
                 $imgSource = imagecreatefrompng(self::$file['tmp_name']);
                 $width = imagesx($imgSource);
                 $height = imageSY($imgSource);
                 $im = imagecreatetruecolor($width, $height);
                 imagealphablending($im, false);
                 $colorTransparent = imagecolorallocatealpha($im, 0, 0, 0, 0x7fff0000);
                 imagefill($im, 0, 0, $colorTransparent);
                 imagesavealpha($im, true);
                 imagecopyresized($im, $imgSource, 0, 0, 0, 0, $width, $height, $width, $height);
                 imagepng($im, removeMultiple($destination . "/" . self::$name));
                 break;
             case 'gif':
                 $img = imagecreatefromgif(self::$file['tmp_name']);
                 imagegif($img, removeMultiple($destination . "/" . self::$name));
                 break;
             case 'bmp':
                 $img = imagecreatefromwbmp(self::$file['tmp_name']);
                 imagewbmp($img, removeMultiple($destination . "/" . self::$name));
                 break;
             default:
                 move_uploaded_file(self::$file['tmp_name'], removeMultiple($destination . "/" . self::$name));
                 break;
         }
         $imageSize = getimagesize(removeMultiple($destination . "/" . self::$name));
         $img = Image::make(removeMultiple($destination . "/" . self::$name));
         self::$tmpPath = removeMultiple($destination . "/" . self::$name);
         if (!empty(self::$resize)) {
             $img->resize(self::$resize['Width'], self::$resize['Height']);
             $img->save(removeMultiple($destination . "/" . self::$name));
         } else {
             if ($imageSize[0] > self::$maxImageSize['Width']) {
                 $img->resize(self::$maxImageSize['Width'], null, function ($constraint) {
                     $constraint->aspectRatio();
                 });
                 $img->save(removeMultiple($destination . "/" . self::$name));
             } else {
                 if ($imageSize[1] > self::$maxImageSize['Height']) {
                     $img->resize(null, self::$maxImageSize['Height'], function ($constraint) {
                         $constraint->aspectRatio();
                     });
                     $img->save(removeMultiple($destination . "/" . self::$name));
                 }
             }
         }
     } else {
         move_uploaded_file(self::$file['tmp_name'], removeMultiple($destination . "/" . self::$name));
     }
     self::reset();
     return new self();
 }
Beispiel #2
0
 /**
  * Menampilkan dropdown yang berisi hari, sumber data berasal dari Config
  * @param string    $name          nama input
  * @param string    $selected      option yang akan terpilih
  * @param array     $attributes    attribute input
  */
 public static function dropDownDay($name, $selected, $attributes)
 {
     return self::dropDown($name, Config::Get("Config", "Form")['DropDownDay'], $selected, $attributes);
 }