* $options['width'] = ''; * $options['height'] = ''; * $options['global'] = '';// 是否显示 global 目录(公共目录) * $options['extras'] = array( *  'image'=> 缩略图img标签的自定义属性及属性值 , *  'text'=> input 标签的自定义属性及属性值 * ) * * @return string */ public static function tplFormFieldImage($name, $value = '', $default = '', $options = array()) { if (empty($default)) { $default = static_url('resource/images/nopic.jpg'); } $val = $default; if (!empty($value)) { $val = yz_tomedia($value); } if (!empty($options['global'])) { $options['global'] = true; } else { $options['global'] = false; } if (empty($options['class_extra'])) { $options['class_extra'] = ''; } if (isset($options['dest_dir']) && !empty($options['dest_dir'])) { if (!preg_match('/^\w+([\/]\w+)?$/i', $options['dest_dir'])) { exit('图片上传目录错误,只能指定最多两级目录,如: "yz_store","yz_store/d1"'); } } $options['direct'] = true; $options['multiple'] = false; if (isset($options['thumb'])) { $options['thumb'] = !empty($options['thumb']); } $param = uploadParam(); $options['fileSizeLimit'] = $param['fileSizeLimitImage']; $s = ''; if (!defined('TPL_INIT_IMAGE')) { $s = ' '; define('TPL_INIT_IMAGE', true); } $s .= '
×
'; return $s; } /** * 批量上传图片 * @param string $name 表单input名称 * @param array $value 附件路径信息 * @param array $options 自定义图片上传路径 * @return string */ public static function tplFormFieldMultiImage($name, $value = array(), $options = array()) { $options['multiple'] = true; $options['direct'] = false; $param = uploadParam(); $options['fileSizeLimit'] = $param['fileSizeLimitImage']; if (isset($options['dest_dir']) && !empty($options['dest_dir'])) { if (!preg_match('/^\w+([\/]\w+)?$/i', $options['dest_dir'])) { exit('图片上传目录错误,只能指定最多两级目录,如: "yz_store","yz_store/d1"'); } } $s = ''; if (!defined('TPL_INIT_MULTI_IMAGE')) { $s = ' '; define('TPL_INIT_MULTI_IMAGE', true); } $s .= <<
EOF; if (is_array($value) && count($value) > 0) { foreach ($value as $row) { $s .= '
×
'; } } $s .= '
'; return $s; } /** * 【表单控件】: 视频上传与选择控件 * @param string $name 表单input名称 * @param string $value 表单input值 * @param string $default 默认显示的缩略图 * @param array $options * @return string */ public function tplFormFieldVideo($name, $value = '', $options = array()) { if(!is_array($options)){ $options = array(); } $options['direct'] = true; $options['multi'] = false; $options['type'] = 'video'; $param = uploadParam(); $options['fileSizeLimit'] = $param['fileSizeLimitAudio']; $s = ''; if (!defined('TPL_INIT_VIDEO')) { $s = ' '; echo $s; define('TPL_INIT_VIDEO', true); } $s .= '
'; return $s; } /** * 前端组件上传图片 * * @param $fileinput * @return null|string */ public static function upload($fileinput, $dir = 'upload') { if (\Request::isMethod('post')) { $file = \Request::file($fileinput); if ($file->isValid()) { // 获取文件相关信息 $originalName = $file->getClientOriginalName(); // 文件原名 $realPath = $file->getRealPath(); //临时文件的绝对路径 $bool = \Storage::disk($dir)->put($originalName, file_get_contents($realPath)); return $bool ? $originalName : ''; } } } public static function fix_wechatAvatar($avatar) { return preg_replace('/132132/', '132', $avatar); } public static function iosWechatAvatar($avatar) { $osType = Client::osType(); if ($osType == Client::OS_TYPE_IOS || $osType == Client::OS_TYPE_ANDROID) { return preg_replace("/^http:/i","https:", $avatar); } return $avatar; } public static function getImageUrl($file) { if (config('app.framework') == 'platform') { return request()->getSchemeAndHttpHost() . DIRECTORY_SEPARATOR . substr($file, strpos($file, 'storage')); } else { return request()->getSchemeAndHttpHost() . DIRECTORY_SEPARATOR . substr($file, strpos($file, 'addons')); } } }