source: pro-violet-viettel/www/deploy/api/platform/lib/violetUtil.class.php @ 902

Last change on this file since 902 was 902, checked in by quyenla, 10 years ago

webroot

File size: 2.7 KB
Line 
1<?php
2
3/**
4 * Utility functions for violet application
5 *
6 */
7class violetUtil {
8
9  public static function getSpacePath($absolute = true) {
10    if ($absolute) {
11      return sfConfig::get('sf_upload_dir').'/'.sfConfig::get('app_space_dir').'/';
12    } else {
13      return sfConfig::get('sf_upload_dir_name').'/'.sfConfig::get('app_space_dir').'/';
14    }
15  }
16
17  public static function getTempPath($subDir = '', $create = false) {
18    $tempPath = sfConfig::get('sf_upload_dir') .'/'. sfConfig::get('app_temp_dir') .'/'. $subDir;
19    if ($create && !file_exists($tempPath)) mkdir($tempPath, 0777, true);
20    return $tempPath;
21  }
22
23  public static function getContentType($fileType) {
24    switch (strtolower($fileType)) {
25      case 'xml':
26      case 'xvl': return 'text/xml';
27
28      case 'jpe':
29      case 'jpg':
30      case 'jpeg': return 'image/jpeg';
31      case 'gif': return 'image/gif';
32      case 'png': return 'image/png';
33
34      case 'flv': return 'video/x-flv';
35      case 'mp4': return 'video/mp4';
36      case 'mp3': return 'audio/mpeg';
37      case 'swf': return 'application/x-shockwave-flash';
38    }
39  }
40   public function createThumb($pathToImage="") {
41
42        if (is_file($pathToImage)) {
43     
44            $info = pathinfo($pathToImage);
45            $extension = strtolower($info['extension']);
46           
47            if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
48
49                switch ($extension) {
50                    case 'jpg':
51                        $img = imagecreatefromjpeg("{$pathToImage}");
52                        break;
53                    case 'jpeg':
54                        $img = imagecreatefromjpeg("{$pathToImage}");
55                        break;
56                    case 'png':
57                        $img = imagecreatefrompng("{$pathToImage}");
58                        break;
59                    case 'gif':
60                        $img = imagecreatefromgif("{$pathToImage}");
61                        break;
62                    default:
63                        $img = imagecreatefromjpeg("{$pathToImage}");
64                }
65                list($width, $height) = getimagesize($pathToImage);
66                $new_width = 64;
67                $new_height = 50;
68                $image_p = imagecreatetruecolor($new_width, $new_height);
69         
70                imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
71                $thumnail = $info['dirname']."/".$info['filename']."_thumb.jpg";
72                imagejpeg($image_p,$thumnail, 30);
73                return str_replace($_SERVER['DOCUMENT_ROOT'], "", $thumnail);
74            } else {
75                return "";
76            }
77        } else {
78            return "";
79        }
80       
81        return sfView::NONE;
82    }
83}
Note: See TracBrowser for help on using the repository browser.