Example #1
0
 public static function upload($file, $path = "", $fileName = NULL, $_mime = NULL)
 {
     //----------------------------------------------------------
     //init var
     //----------------------------------------------------------
     $chk = array("bool" => true, 'result' => array(), "func" => "upload");
     //----------------------------------------------------------
     $mime = FileFolder::getMimeType($file);
     if (!is_null($_mime)) {
         $mime = $_mime;
     }
     //----------------------------------------------------------
     $client = S3Client::factory(array('credentials' => array('key' => S3::$key, 'secret' => S3::$secret)));
     //----------------------------------------------------------
     try {
         $chk['result'] = $client->putObject(['Bucket' => S3::$bucket, 'Key' => $path . (!is_null($fileName) ? $fileName : basename($file)), 'Body' => fopen($file, r), 'ACL' => 'public-read', 'ContentType' => $mime]);
     } catch (S3Exception $e) {
         $chk['bool'] = false;
         $chk['message'] = "upload to s3 bucket: " . S3::$bucket . " failed!!!";
     }
     //----------------------------------------------------------
     return $chk;
 }
Example #2
0
 protected function orient_image($file_path)
 {
     if (!function_exists('exif_read_data')) {
         return false;
     }
     $mime = FileFolder::getMimeType($file_path);
     if ($mime == "image/jpeg" || $mime == "image/tiff" || $mime == "image/x-tiff") {
         $exif = @exif_read_data($file_path);
     } else {
         $exif = false;
     }
     if ($exif === false) {
         return false;
     }
     $orientation = intval(@$exif['Orientation']);
     if (!in_array($orientation, array(3, 6, 8))) {
         return false;
     }
     $image = @imagecreatefromjpeg($file_path);
     switch ($orientation) {
         case 3:
             $image = @imagerotate($image, 180, 0);
             break;
         case 6:
             $image = @imagerotate($image, 270, 0);
             break;
         case 8:
             $image = @imagerotate($image, 90, 0);
             break;
         default:
             return false;
     }
     $success = imagejpeg($image, $file_path);
     // Free up memory (imagedestroy does not delete files):
     @imagedestroy($image);
     return $success;
 }