示例#1
0
 public function image($request_name, $extensions, $size, $throw = false)
 {
     $file_source = isset($_FILES[$request_name]) ? $_FILES[$request_name] : null;
     if ($file_source == null) {
         return false;
     }
     list($width, $height, $type) = getimagesize($file_source['tmp_name']);
     if (isset($type) && !in_array($type, self::$image_types)) {
         return false;
     }
     $ext = explode(".", $file_source["name"]);
     $file_extension = strtolower(end($ext));
     if (in_array($file_extension, $extensions) == false) {
         return false;
     }
     if ($file_source['size'] > $size * 1024 * 1024) {
         return false;
     }
     $file_name = $this->getRandomName();
     $destination = self::UPLOADS_DIRECTORY . '/' . $file_name . '.' . $file_extension;
     move_uploaded_file($file_source['tmp_name'], $destination);
     if ($_GET['channel'] == self::CHANNEL_APP) {
         $compression_type = Imagick::COMPRESSION_JPEG;
         $thumbnail = new Imagick($destination);
         $thumbnail->setImageCompression($compression_type);
         $thumbnail->setImageCompressionQuality(75);
         $thumbnail->stripImage();
         $image_width = $thumbnail->getImageWidth();
         $width = min($image_width, 800);
         $thumbnail->thumbnailImage($width, null);
         App_Controller_Site_Images::delete($destination);
         $thumbnail->writeImage($destination);
     }
     $time = date('Y-m-d H:i:s');
     $ip = $_SERVER['REMOTE_ADDR'];
     $channel = self::CHANNEL_WEB;
     if (isset($_GET['channel']) && ($_GET['channel'] == self::CHANNEL_APP || $_GET['channel'] == self::CHANNEL_WEB)) {
         $channel = $_GET['channel'];
     }
     $query = "INSERT INTO `uploads` (`src`,`upload_time`,`token`,`ip`,`channel`) VALUES ('{$destination}','{$time}','{$file_name}','{$ip}','{$channel}')";
     App_Db::getInstance()->getConn()->query($query);
     return $file_name;
 }
示例#2
0
 public function indexAction()
 {
     $token = $_GET['file_token'];
     if (preg_match('/^([A-Z0-9a-z]{7})$/i', $token) == false) {
         App_Headers::redirect(array());
     }
     $query = "SELECT * FROM `uploads` WHERE `token` = '{$token}'";
     $result = App_Db::getInstance()->getConn()->query($query);
     $imageModel = $result->fetchObject();
     if (empty($imageModel) || !empty($imageModel) && $imageModel->is_deleted) {
         return null;
     }
     $time = date('Y-m-d H:i:s');
     $query = "UPDATE `uploads` SET `is_deleted` = '1',`time_open`='{$time}' WHERE id = '{$imageModel->id}'";
     $result = App_Db::getInstance()->getConn()->query($query);
     $imageData = base64_encode(file_get_contents($imageModel->src));
     $src = 'data: ' . $this->getMimeType($imageModel->src) . ';base64,' . $imageData;
     self::delete($imageModel->src);
     $this->_view->image_src = $src;
 }
示例#3
0
文件: auth.php 项目: nexces/transys
 public function __construct()
 {
     $this->_oDbAdapter = App_Db::getInstance()->getAdapter();
 }
示例#4
0
文件: Base.php 项目: gilad1987/picabo
 public function getCount()
 {
     return App_Db::getInstance()->getConn()->query("SELECT COUNT(`id`) as `counter` FROM {$this->tableName}")->fetchObject()->counter;
 }