示例#1
0
/**
 * 获取图片
 * @param int $id
 * @param string $field
 * @return 完整的数据  或者  指定的$field字段值
 * @author huajie <*****@*****.**>
 */
function get_picture($id = null, $field = null, $wh = null)
{
    $revalue = '';
    $id = trim($id);
    if (empty($id)) {
        $revalue = false;
    }
    if (is_numeric($id)) {
        $cakey = md5($id . '_' . $field . '_' . $wh);
        //$revalue=F('_picture/'.$cakey);
        $pkey = '_picture/' . $id % 100;
        $picarr = F($pkey);
        $revalue = $picarr[$cakey];
        if (empty($revalue) || APP_DEBUG) {
            $picture = M('Picture')->where(array('status' => 1))->getById($id);
            if (!empty($field) && !empty($wh)) {
                $wharr = explode('_', $wh);
                if (count($wharr == 2)) {
                    $revalue = str_replace('/Uploads/image/', IMAGE_CACHE_DIR, $picture['path']);
                    $revalue = substr($revalue, 0, strrpos($revalue, '.')) . '_' . $wh . substr($revalue, strrpos($revalue, '.'));
                    //判断之前是不是已经生成
                    if (!file_exists(path_a($revalue))) {
                        $result = create_thumb(path_a($picture['path']), path_a($revalue), $wharr[0], $wharr[1]);
                        if ($result !== true) {
                            $revalue = $picture['path'];
                        }
                    }
                }
            } else {
                if (!empty($field)) {
                    $revalue = $picture[$field];
                    if ($field == 'thumbpath') {
                        if (!file_exists(path_a($revalue))) {
                            $result = create_thumb(path_a($picture['path']), path_a($revalue), C('THUMB_WIDTH'), C('THUMB_HEIGHT'));
                            if ($result !== true) {
                                $revalue = $picture['path'];
                            }
                        }
                    }
                } else {
                    $revalue = $picture['path'];
                }
            }
            $picarr[$cakey] = $revalue;
            F($pkey, $picarr);
        }
    } else {
        $revalue = $id;
    }
    return empty($revalue) ? '' : path_r($revalue);
}
示例#2
0
 /**
  *输出资源到文件中
  **/
 public function registerend()
 {
     //查找真实路径,先从当前模块查找
     $ismodcss = false;
     $ismodjs = false;
     if (empty($this->css) && empty($this->js)) {
         return "";
     }
     $cssname = md5(implode($this->css));
     $jsname = md5(implode($this->js));
     $suijinum = F('assetsversion');
     if (empty($suijinum) || APP_DEBUG) {
         $suijinum = '?r=' . rand(10000, 99999);
         F('assetsversion', $suijinum);
     }
     $csscache = STYLE_CACHE_DIR . MODULE_NAME . '/' . $cssname . '.css';
     $jscache = STYLE_CACHE_DIR . MODULE_NAME . '/' . $jsname . '.js';
     //查找css文件
     foreach ($this->css as $k => $v) {
         $filepath = $this->getFilePath($v, 'css');
         if ($filepath) {
             $this->css[$k] = $filepath;
             if (APP_DEBUG) {
                 $this->cssstr .= '<link href="' . $filepath . $suijinum . '" type="text/css" rel="stylesheet" />' . "\n";
             } else {
                 if (file_ismod('.' . $filepath) || !file_exists($csscache)) {
                     $ismodcss = true;
                     $this->cssstr .= $this->compress_css('.' . $filepath);
                 }
             }
         } else {
             $this->css[$k] .= '.css--->file is not exists!';
         }
     }
     //查找js文件
     foreach ($this->js as $k => $v) {
         $filepath = $this->getFilePath($v, 'js');
         if ($filepath) {
             $this->js[$k] = $filepath;
             if (APP_DEBUG) {
                 $this->jsstr .= '<script src="' . $filepath . $suijinum . '" type="text/javascript" ></script>' . "\n";
             } else {
                 if (file_ismod('.' . $filepath) || !file_exists($jscache)) {
                     $ismodjs = true;
                     $this->jsstr .= $this->compress_js('.' . $filepath);
                 }
             }
         } else {
             $this->js[$k] .= '.js--->file is not exists!';
         }
     }
     if (!APP_DEBUG) {
         if (!file_exists(dirname($csscache))) {
             mkdir(dirname($csscache), 0777, true);
         }
         if (!file_exists(dirname($jscache))) {
             mkdir(dirname($jscache), 0777, true);
         }
         ($ismodcss || !file_exists($csscache)) && file_put_contents($csscache, $this->cssstr);
         ($ismodjs || !file_exists($jscache)) && file_put_contents($jscache, $this->jsstr);
         if (!empty($this->css)) {
             $this->cssstr = '<link href="' . path_r($csscache) . $suijinum . '" type="text/css" rel="stylesheet" />' . "\n";
         }
         if (!empty($this->js)) {
             $this->jsstr = '<script src="' . path_r($jscache) . $suijinum . '" type="text/javascript" ></script>' . "\n";
         }
     }
     return $this->cssstr . $this->jsstr;
 }
示例#3
0
function thumbnail_path($width, $key_filename)
{
    global $thumbnail_directory;
    return path_r($thumbnail_directory) . "/" . thumbnail_basename($width, $key_filename);
}
示例#4
0
 /**
  * 上传图片
  * @author huajie <*****@*****.**>
  */
 public function uploadpic()
 {
     //TODO: 用户登录检测
     /* 返回标准数据 */
     $return = array('status' => 1, 'srcname' => $_FILES['filelist']['name'], 'destname' => '', 'info' => '上传成功', 'path' => '', 'id' => '', 'url' => '', 'data' => '');
     $SITE_PATH = SITE_PATH;
     //网站根目录
     $targetFolder = path_a(C('FILE_UPLOAD.rootPath'));
     //保存图片的根目录
     $JDtargetPath = '';
     $data = array();
     if (!empty($_FILES)) {
         $tempFile = $_FILES['filelist']['tmp_name'];
         //生成的文件名字
         $extend = explode(".", strtolower($_FILES['filelist']['name']));
         $va = count($extend) - 1;
         $filename = time() . mt_rand(10000, 99999) . "." . $extend[$va];
         //文件类型文件夹
         $foldertype = '';
         switch ($extend[$va]) {
             case 'jpg':
                 $targetFolder .= '/image';
                 $foldertype = '/thumb';
                 break;
             case 'png':
                 $targetFolder .= '/image';
                 $foldertype = '/thumb';
                 break;
             case 'gif':
                 $targetFolder .= '/image';
                 $foldertype = '/thumb';
                 break;
             case 'jpeg':
                 $targetFolder .= '/image';
                 $foldertype = '/thumb';
                 break;
             case 'bmp':
                 $targetFolder .= '/image';
                 $foldertype = '/thumb';
                 break;
             case 'mp4':
                 $targetFolder .= '/file/video';
                 break;
             default:
                 $targetFolder .= '/file/other';
                 break;
         }
         $imgpath = $targetFolder . '/' . date('Ymd');
         if (!create_folder($imgpath)) {
             $return['info'] = '创建目录错误:' . $imgpath;
             $return['status'] = 0;
             $this->ajaxreturn($return);
         }
         $imgpath2 = $targetFolder . $foldertype . '/' . date('Ymd');
         if (!create_folder($imgpath)) {
             $return['info'] = '创建目录错误:' . $imgpath;
             $return['status'] = 0;
             $this->ajaxreturn($return);
         }
         $JDtargetPath = $targetFolder . '/' . date('Ymd') . '/' . $filename;
         // Validate the file type
         $fileTypes = array('jpg', 'jpeg', 'gif', 'png');
         // File extensions
         if (in_array($extend[$va], $fileTypes)) {
             $bl = move_uploaded_file($tempFile, $JDtargetPath);
             $JDthumbPath = str_replace('/image/', '/image/thumb/', $JDtargetPath);
             if ($bl) {
                 //判断是不是已经上传过类似图片
                 $shafile = $this->checksha(str_replace($SITE_PATH, '', $JDtargetPath));
                 $JDtargetPath = $SITE_PATH . $shafile['path'];
                 $data['sha1'] = $shafile['sha1'];
                 //如果是图片就生成缩略图
                 if (in_array($extend[$va], array('jpg', 'jpeg', 'gif', 'png', 'bmp'))) {
                     //生成缩略图
                     //缩略图路径
                     $re = create_thumb($JDtargetPath, $JDthumbPath, C('THUMB_WIDTH'), C('THUMB_HEIGHT'));
                     if ($re !== true) {
                         $JDthumbPath = $JDtargetPath;
                     }
                 }
                 $return['path'] = path_r($JDthumbPath);
             } else {
                 $return['info'] = '上传错误' . $tempFile . '->' . $JDtargetPath;
                 $return['status'] = 0;
             }
         } else {
             $return['info'] = '不支持此文件类型';
             $return['status'] = 0;
         }
     } else {
         $return['info'] = "文件不能为空";
         $return['status'] = 0;
     }
     if ($return['status'] == 1) {
         //保存文件信息到数据库
         $cupath = path_r($JDtargetPath);
         $data['path'] = $cupath;
         //$data['sha1']        = $shafile['sha1'];
         $data['thumbpath'] = path_r($JDthumbPath);
         $data['destname'] = $filename;
         $data['srcname'] = $_FILES['filelist']['name'];
         $data['create_time'] = time();
         $data['uid'] = UID;
         $model = M('picture');
         if ($model->create($data)) {
             $result = $model->add($data);
             if ($result) {
                 //添加水印
                 $this->markpic($JDthumbPath);
                 $this->markpic(realpath('.' . $data['path']));
                 $return['id'] = $result;
             }
         }
     }
     /* 返回JSON数据 */
     $this->ajaxReturn(array_merge($return, $data));
 }