本文整理汇总了PHP中Typecho_Common::mimeContentType方法的典型用法代码示例。如果您正苦于以下问题:PHP Typecho_Common::mimeContentType方法的具体用法?PHP Typecho_Common::mimeContentType怎么用?PHP Typecho_Common::mimeContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Typecho_Common
的用法示例。
在下文中一共展示了Typecho_Common::mimeContentType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadHandle
/**
* 上传文件处理函数,如果需要实现自己的文件哈希或者特殊的文件系统,请在options表里把uploadHandle改成自己的函数
*
* @access public
* @param array $file 上传的文件
* @return mixed
*/
public static function uploadHandle($file)
{
if (empty($file['name'])) {
return false;
}
$result = Typecho_Plugin::factory('Widget_Upload')->trigger($hasUploaded)->uploadHandle($file);
if ($hasUploaded) {
return $result;
}
$fileName = preg_split("(\\/|\\|:)", $file['name']);
$file['name'] = array_pop($fileName);
//获取扩展名
$ext = '';
$part = explode('.', $file['name']);
if (($length = count($part)) > 1) {
$ext = strtolower($part[$length - 1]);
}
if (!self::checkFileType($ext)) {
return false;
}
$options = Typecho_Widget::widget('Widget_Options');
$date = new Typecho_Date($options->gmtTime);
$path = Typecho_Common::url(self::UPLOAD_PATH, __TYPECHO_ROOT_DIR__) . '/' . $date->year . '/' . $date->month;
//创建上传目录
if (!is_dir($path)) {
if (!self::makeUploadDir($path)) {
return false;
}
}
//获取文件名
$fileName = sprintf('%u', crc32(uniqid())) . '.' . $ext;
$path = $path . '/' . $fileName;
if (isset($file['tmp_name'])) {
//移动上传文件
if (!@move_uploaded_file($file['tmp_name'], $path)) {
return false;
}
} else {
if (isset($file['bytes'])) {
//直接写入文件
if (!file_put_contents($path, $file['bytes'])) {
return false;
}
} else {
return false;
}
}
if (!isset($file['size'])) {
$file['size'] = filesize($path);
}
//返回相对存储路径
return array('name' => $file['name'], 'path' => self::UPLOAD_PATH . '/' . $date->year . '/' . $date->month . '/' . $fileName, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($path));
}
示例2: uploadFile
public static function uploadFile($file, $content = null)
{
// 获取上传文件
if (empty($file['name'])) {
return false;
}
// 校验扩展名
$part = explode('.', $file['name']);
$ext = ($length = count($part)) > 1 ? strtolower($part[$length - 1]) : '';
if (!Widget_Upload::checkFileType($ext)) {
return false;
}
// 获取插件配置
$option = self::getConfig();
$date = new Typecho_Date(Typecho_Widget::widget('Widget_Options')->gmtTime);
// 保存位置
$savepath = preg_replace(array('/\\{year\\}/', '/\\{month\\}/', '/\\{day\\}/'), array($date->year, $date->month, $date->day), $option->savepath);
$savename = $savepath . sprintf('%u', crc32(uniqid())) . '.' . $ext;
if (isset($content)) {
$savename = $content['attachment']->path;
self::deleteFile($savename);
}
// 上传文件
$filename = $file['tmp_name'];
if (!isset($filename)) {
return false;
}
// 初始化 SDK
$token = self::init($option->accesskey, $option->sercetkey)->uploadToken($option->bucket);
// 上传
$uploadMgr = new Qiniu\Storage\UploadManager();
list($result, $error) = $uploadMgr->putFile($token, $savename, $filename);
if ($error == null) {
return array('name' => $file['name'], 'path' => $savename, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($savename));
} else {
var_dump($error);
return false;
}
}
示例3: uploadAvatar
/**
* 上传头像
* @param array $file
* @return boolean|multitype:string unknown number Ambigous <string, unknown> Ambigous <Ambigous, string, mixed>
*/
private function uploadAvatar($file)
{
if (empty($file['name'])) {
return false;
}
$ext = $this->getSafeName($file['name']);
if (!Widget_Upload::checkFileType(strtolower($ext)) || Typecho_Common::isAppEngine()) {
return false;
}
$options = Typecho_Widget::widget('Widget_Options');
$path = Widget_Common::getAvatarPath($this->user->uid);
$realPath = Typecho_Common::url($path, defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__);
//创建上传目录
if (!is_dir($realPath)) {
if (!$this->makeAvatarDir($realPath)) {
return false;
}
}
//获取文件名
$fileName = $this->user->uid . '.tmp.' . $ext;
$realPath = $realPath . '/' . $fileName;
if (isset($file['tmp_name'])) {
//移动上传文件
if (!@move_uploaded_file($file['tmp_name'], $realPath)) {
return false;
}
} else {
if (isset($file['bytes'])) {
//直接写入文件
if (!file_put_contents($realPath, $file['bytes'])) {
return false;
}
} else {
return false;
}
}
if (!isset($file['size'])) {
$file['size'] = filesize($realPath);
}
//返回相对存储路径
return array('name' => $file['name'], 'path' => $path, 'file' => $path . $fileName, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($realPath));
}
示例4: uploadHandle
/**
* 上传文件处理函数
*
* @access public
* @param array $file 上传的文件
* @return mixed
*/
public static function uploadHandle($file)
{
if (empty($file['name'])) {
return false;
}
$fileName = preg_split("(\\/|\\|:)", $file['name']);
$file['name'] = array_pop($fileName);
//获取扩展名
$ext = '';
$part = explode('.', $file['name']);
if (($length = count($part)) > 1) {
$ext = strtolower($part[$length - 1]);
}
if (!self::checkFileType($ext)) {
return false;
}
//获取文件名
$fileName = sprintf('%u', crc32(uniqid())) . '.' . $ext;
$path = $path . '/' . $fileName;
//add for mkdir
$stor = new SaeStorage();
$options = Typecho_Widget::widget('Widget_Options');
$SaeStorageDomain = $options->plugin('SaeUpload')->saestoragedomain;
if (isset($file['tmp_name'])) {
//移动上传文件
if (!($path = $stor->upload($SaeStorageDomain, $fileName, $file['tmp_name']))) {
return false;
}
} else {
if (isset($file['bits'])) {
//直接写入文件
if (!($path = $stor->write($SaeStorageDomain, $fileName, $file['bits']))) {
return false;
}
} else {
return false;
}
}
if (!isset($file['size'])) {
$attr = $stor->getAttr($SaeStorageDomain, $fileName, array('length'));
$file['size'] = $attr['length'];
}
//返回相对存储路径
return array('name' => $file['name'], 'path' => $fileName, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($path));
}
示例5: uploadFile
public static function uploadFile($file, $content = null)
{
// 获取上传文件
if (empty($file['name'])) {
return false;
}
$option = self::getConfig();
if (!isset($option->accessid)) {
return false;
}
self::initSDK();
$obj = new ALIOSS($option->accessid, $option->accesskey, $option->endpoint);
// 校验扩展名
$part = explode('.', $file['name']);
$ext = ($length = count($part)) > 1 ? strtolower($part[$length - 1]) : '';
if (!Widget_Upload::checkFileType($ext)) {
return false;
}
// 保存位置
$savename = str_replace(array('{year}', '{month}', '{day}'), array(date('Y'), date('m'), date('d')), ltrim(self::isImage($ext) ? $option->savepath : $option->nonimg_savepath, '/')) . sprintf('%u', crc32(uniqid())) . '.' . $ext;
$response = $obj->upload_file_by_file($option->bucket, $savename, $file['tmp_name']);
if ($response->status === 200) {
return array('name' => $file['name'], 'path' => $savename, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($savename));
}
return false;
}
示例6: uploadHandle
/**
* 上传文件处理函数,如果需要实现自己的文件哈希或者特殊的文件系统,请在options表里把uploadHandle改成自己的函数
*
* @access public
* @param array $file 上传的文件
* @return mixed
*/
public static function uploadHandle($file)
{
if (empty($file['name'])) {
return false;
}
$result = Typecho_Plugin::factory('Widget_Upload')->trigger($hasUploaded)->uploadHandle($file);
if ($hasUploaded) {
return $result;
}
$ext = self::getSafeName($file['name']);
if (!self::checkFileType($ext) || Typecho_Common::isAppEngine()) {
return false;
}
$options = Typecho_Widget::widget('Widget_Options');
$date = new Typecho_Date($options->gmtTime);
$path = Typecho_Common::url(defined('__TYPECHO_UPLOAD_DIR__') ? __TYPECHO_UPLOAD_DIR__ : self::UPLOAD_DIR, defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__) . '/' . $date->year . '/' . $date->month;
//创建上传目录
if (!is_dir($path)) {
if (!self::makeUploadDir($path)) {
return false;
}
}
//获取文件名
$fileName = sprintf('%u', crc32(uniqid())) . '.' . $ext;
$path = $path . '/' . $fileName;
if (isset($file['tmp_name'])) {
//移动上传文件
if (!@move_uploaded_file($file['tmp_name'], $path)) {
return false;
}
} else {
if (isset($file['bytes'])) {
//直接写入文件
if (!file_put_contents($path, $file['bytes'])) {
return false;
}
} else {
return false;
}
}
if (!isset($file['size'])) {
$file['size'] = filesize($path);
}
//返回相对存储路径
return array('name' => $file['name'], 'path' => (defined('__TYPECHO_UPLOAD_DIR__') ? __TYPECHO_UPLOAD_DIR__ : self::UPLOAD_DIR) . '/' . $date->year . '/' . $date->month . '/' . $fileName, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($path));
}
示例7: uploadHandle
/**
* 上传文件处理函数
*
* @access public
* @param array $file 上传的文件
* @return mixed
*/
public static function uploadHandle($file)
{
if (empty($file['name'])) {
return false;
}
//获取扩展名
$ext = self::getSafeName($file['name']);
if (!Widget_Upload::checkFileType($ext) || Typecho_Common::isAppEngine()) {
return false;
}
$options = Typecho_Widget::widget('Widget_Options');
$date = new Typecho_Date($options->gmtTime);
//构建路径 /year/month/
$path = '/' . $date->year . '/' . $date->month;
$settings = $options->plugin('UpyunFile');
if ($settings->mode == 'typecho') {
$path = self::getUploadDir() . $path;
}
//获取文件名及文件路径
$fileName = sprintf('%u', crc32(uniqid())) . '.' . $ext;
$path = $path . '/' . $fileName;
$uploadfile = isset($file['tmp_name']) ? $file['tmp_name'] : (isset($file['bits']) ? $file['bits'] : FALSE);
if ($uploadfile == FALSE) {
return false;
} else {
//上传文件
$upyun = self::upyunInit();
$fh = fopen($uploadfile, 'rb');
$upyun->writeFile($path, $fh, TRUE);
fclose($fh);
}
if (!isset($file['size'])) {
$fileInfo = $upyun->getFileInfo($path);
$file['size'] = $fileInfo['x-upyun-file-size'];
}
//返回相对存储路径
return array('name' => $file['name'], 'path' => $path, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($path));
}
示例8: ScsUpload
/**
* 上传附件
*
* @static
* @access public
* @return bool
* @throws Typecho_Plugin_Exception
*/
public static function ScsUpload($file, $content = null)
{
if (empty($file['name'])) {
return false;
}
//获取安全的文件名后缀
$ext = self::getSafeName($file['name']);
if (!Widget_Upload::checkFileType($ext)) {
return false;
}
$option = self::getSCSconfig();
$date = new Typecho_Date(Typecho_Widget::widget('Widget_Options')->gmtTime);
$path = $option->format == null ? $date->year . '/' . $date->month . '/' : preg_replace(array('/\\{year\\}/', '/\\{month\\}/', '/\\{day\\}/'), array($date->year, $date->month, $date->day), self::getSCSFilepath($option->format));
/*非必须(在本地附件目录/usr/uploads/下创建新目录)
if (!is_dir($path)) {
if (!self::makeUploadDir($path)) {
return false;
}
}
*/
//以Unix time stamp形式储存:$path .= sprintf('%u', crc32(uniqid())) . '.' . $ext;
$path .= $file['name'];
if (isset($content)) {
$path = $content['attachment']->path;
self::ScsDelete($path);
}
$clienttmp = $file['tmp_name'];
if (!isset($clienttmp)) {
return false;
}
self::getSCSsdk();
$scs = new SCS($option->accesskey, $option->secretkey);
if ($scs->putObjectFile($clienttmp, $option->bucket, $path, SCS::ACL_PUBLIC_READ)) {
return array('name' => $file['name'], 'path' => $path, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($path));
} else {
return false;
}
}
示例9: uploadHandle
/**
* 上传文件处理函数
*
* @access public
* @param array $file 上传的文件
* @return mixed
*/
public static function uploadHandle($file)
{
if (empty($file['name'])) {
return false;
}
$fileName = preg_split("(\\/|\\|:)", $file['name']);
$file['name'] = array_pop($fileName);
//获取扩展名
$ext = '';
$part = explode('.', $file['name']);
if (($length = count($part)) > 1) {
$ext = strtolower($part[$length - 1]);
}
if (!Widget_Upload::checkFileType($ext)) {
return false;
}
$options = Typecho_Widget::widget('Widget_Options');
$date = new Typecho_Date($options->gmtTime);
//构建路径
$path = Widget_Upload::UPLOAD_PATH . '/' . $date->year . '/' . $date->month;
//获取文件名
$fileName = sprintf('%u', crc32(uniqid())) . '.' . $ext;
$path = $path . '/' . $fileName;
$bcs = self::bcsInit();
$bucket = $options->plugin('BaeUpload')->bucket;
//空日志记录函数
function bcs_log()
{
}
if (isset($file['tmp_name'])) {
//移动上传文件
if (!$bcs->create_object($bucket, $path, $file['tmp_name'], array('acl' => BaiduBCS::BCS_SDK_ACL_TYPE_PUBLIC_READ, BaiduBCS::IMPORT_BCS_LOG_METHOD => 'bcs_log'))->isOK()) {
return false;
}
} else {
if (isset($file['bits'])) {
//直接写入文件
if (!$bcs->create_object_by_content($bucket, $path, $file['bits'], array('acl' => BaiduBCS::BCS_SDK_ACL_TYPE_PUBLIC_READ, BaiduBCS::IMPORT_BCS_LOG_METHOD => 'bcs_log'))->isOK()) {
return false;
}
} else {
return false;
}
}
//设置文件Content-Type
$bcs->set_object_meta($bucket, $path, array('Content-Type' => BCS_MimeTypes::get_mimetype($ext)), array(BaiduBCS::IMPORT_BCS_LOG_METHOD => 'bcs_log'));
if (!isset($file['size'])) {
$file['size'] = $bcs->get_object_info($bucket, $path, array(BaiduBCS::IMPORT_BCS_LOG_METHOD => 'bcs_log'))->header['Content-Length'];
}
//返回相对存储路径
return array('name' => $file['name'], 'path' => $path, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($path));
}