@@ -97,7 +97,7 @@ class FileManagement | |||
/** | |||
* 删除目录 | |||
* | |||
* @param unknown_type $indir | |||
* @param string $indir | |||
*/ | |||
function RmDirFiles($indir) | |||
{ | |||
@@ -120,9 +120,9 @@ class FileManagement | |||
/** | |||
* 获得某目录合符规则的文件 | |||
* | |||
* @param unknown_type $indir | |||
* @param unknown_type $fileexp | |||
* @param unknown_type $filearr | |||
* @param string $indir | |||
* @param string $fileexp | |||
* @param array $filearr | |||
*/ | |||
function GetMatchFiles($indir, $fileexp, &$filearr) | |||
{ | |||
@@ -142,8 +142,8 @@ class FileManagement | |||
/** | |||
* 删除文件 | |||
* | |||
* @param unknown_type $filename | |||
* @return unknown | |||
* @param string $filename | |||
* @return int | |||
*/ | |||
function DeleteFile($filename) | |||
{ | |||
@@ -635,6 +635,101 @@ function AddFilter($channelid, $type=1, $fieldsnamef='', $defaulttid=0, $toptid= | |||
} | |||
echo $dede_addonfields; | |||
} | |||
/** | |||
* GetMimeTypeOrExtension | |||
* | |||
* @param mixed $str 字符串 | |||
* @param mixed $t 类型,0:获取mime type,1:获取扩展名 | |||
* @return string | |||
*/ | |||
function GetMimeTypeOrExtension($str,$t=0) { | |||
$mime_types = array( | |||
'aac' => 'audio/aac', | |||
'abw' => 'application/x-abiword', | |||
'arc' => 'application/x-freearc', | |||
'avi' => 'video/x-msvideo', | |||
'azw' => 'application/vnd.amazon.ebook', | |||
'bin' => 'application/octet-stream', | |||
'bmp' => 'image/bmp', | |||
'bz' => 'application/x-bzip', | |||
'bz2' => 'application/x-bzip2', | |||
'csh' => 'application/x-csh', | |||
'css' => 'text/css', | |||
'csv' => 'text/csv', | |||
'doc' => 'application/msword', | |||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | |||
'eot' => 'application/vnd.ms-fontobject', | |||
'epub' => 'application/epub+zip', | |||
'gif' => 'image/gif', | |||
'htm' => 'text/html', | |||
'html' => 'text/html', | |||
'ico' => 'image/vnd.microsoft.icon', | |||
'ics' => 'text/calendar', | |||
'jar' => 'application/java-archive', | |||
'jpeg' => 'image/jpeg', | |||
'jpg' => 'image/jpeg', | |||
'js' => 'text/javascript', | |||
'json' => 'application/json', | |||
'jsonld' => 'application/ld+json', | |||
'mid' => 'audio/midi', | |||
'midi' => 'audio/midi', | |||
'mjs' => 'text/javascript', | |||
'mp3' => 'audio/mpeg', | |||
'mpeg' => 'video/mpeg', | |||
'mpkg' => 'application/vnd.apple.installer+xml', | |||
'odp' => 'application/vnd.oasis.opendocument.presentation', | |||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet', | |||
'odt' => 'application/vnd.oasis.opendocument.text', | |||
'oga' => 'audio/ogg', | |||
'ogv' => 'video/ogg', | |||
'ogx' => 'application/ogg', | |||
'otf' => 'font/otf', | |||
'png' => 'image/png', | |||
'pdf' => 'application/pdf', | |||
'ppt' => 'application/vnd.ms-powerpoint', | |||
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | |||
'rar' => 'application/x-rar-compressed', | |||
'rtf' => 'application/rtf', | |||
'sh' => 'application/x-sh', | |||
'svg' => 'image/svg+xml', | |||
'swf' => 'application/x-shockwave-flash', | |||
'tar' => 'application/x-tar', | |||
'tif' => 'image/tiff', | |||
'tiff' => 'image/tiff', | |||
'ttf' => 'font/ttf', | |||
'txt' => 'text/plain', | |||
'vsd' => 'application/vnd.visio', | |||
'wav' => 'audio/wav', | |||
'weba' => 'audio/webm', | |||
'webm' => 'video/webm', | |||
'webp' => 'image/webp', | |||
'woff' => 'font/woff', | |||
'woff2' => 'font/woff2', | |||
'xhtml' => 'application/xhtml+xml', | |||
'xls' => 'application/vnd.ms-excel', | |||
'xlsx' => 'application/vnd.ms-excel', | |||
'xml' => 'application/xml', | |||
'xul' => 'application/vnd.mozilla.xul+xml', | |||
'zip' => 'application/zip', | |||
'3gp' => 'video/3gpp', | |||
'3g2' => 'video/3gpp2', | |||
'7z' => 'application/x-7z-compressed', | |||
'wmv' => 'video/x-ms-asf', | |||
'wma' => 'audio/x-ms-wma', | |||
'mov' => 'video/quicktime', | |||
'rm' => 'application/vnd.rn-realmedia', | |||
'mpg' => 'video/mpeg', | |||
'mpga' => 'audio/mpeg', | |||
); | |||
if ($t===0) { | |||
return isset($mime_types[$str])? $mime_types[$str] : 'application/octet-stream'; | |||
} else { | |||
foreach ($mime_types as $key => $value) { | |||
if ($value == $str) return $key; | |||
} | |||
return "dedebiz"; | |||
} | |||
} | |||
//自定义函数接口 | |||
if (file_exists(DEDEINC.'/extend.func.php')) { | |||
require_once(DEDEINC.'/extend.func.php'); | |||
@@ -16,7 +16,7 @@ class TypeUnit | |||
var $artDir; | |||
var $baseDir; | |||
var $idCounter; | |||
var $idArrary; | |||
var $idArray; | |||
var $shortName; | |||
var $CatalogNums; | |||
//php5构造函数 | |||
@@ -26,8 +26,8 @@ class TypeUnit | |||
$this->artDir = $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir']; | |||
$this->baseDir = $GLOBALS['cfg_basedir']; | |||
$this->shortName = $GLOBALS['art_shortname']; | |||
$this->idArrary = ''; | |||
$this->dsql = 0; | |||
$this->idArray = array(); | |||
$this->dsql = $GLOBALS['dsql']; | |||
} | |||
function TypeUnit() | |||
{ | |||
@@ -75,7 +75,6 @@ class TypeUnit | |||
function ListAllType($channel = 0, $nowdir = 0) | |||
{ | |||
global $cfg_admin_channel, $admin_catalogs; | |||
$this->dsql = $GLOBALS['dsql']; | |||
//检测会员有权限的顶级栏目 | |||
if ($cfg_admin_channel == 'array') { | |||
$admin_catalog = join(',', $admin_catalogs); | |||
@@ -244,7 +243,6 @@ class TypeUnit | |||
*/ | |||
function GetSunTypes($id, $channel = 0) | |||
{ | |||
$this->dsql = $GLOBALS['dsql']; | |||
$this->idArray[$this->idCounter] = $id; | |||
$this->idCounter++; | |||
$fid = $id; | |||
@@ -332,7 +330,7 @@ class TypeUnit | |||
*/ | |||
function RmDirFile($indir) | |||
{ | |||
if (!file_exists($indir)) return; | |||
if (!file_exists($indir)) return -1; | |||
$dh = dir($indir); | |||
while ($file = $dh->read()) { | |||
if ($file == "." || $file == "..") { | |||
@@ -69,62 +69,119 @@ if ($action === 'is_need_check_code') { | |||
} | |||
$target_dir = "uploads/";//上传目录 | |||
$type = isset($type)? $type : ''; | |||
$allowedTypes = array('image/png', 'image/jpg', 'image/jpeg'); | |||
//获取允许的扩展 | |||
$mediatype = 0; | |||
$allowedTypes = array(); | |||
if ($type == 'litpic' || $type == 'face') { | |||
$mediatype = 1; | |||
$imgtypes = explode("|", $cfg_imgtype); | |||
foreach ($imgtypes as $value) { | |||
$allowedTypes[] = GetMimeTypeOrExtension($value); | |||
} | |||
} else if ($type == 'soft') { | |||
$mediatype = 4; | |||
$softtypes = explode("|", $cfg_softtype); | |||
foreach ($softtypes as $value) { | |||
$allowedTypes[] = GetMimeTypeOrExtension($value); | |||
} | |||
} else if ($type == 'media') { | |||
$mediatype = 3; | |||
$mediatypes = explode("|", $cfg_mediatype); | |||
foreach ($mediatypes as $value) { | |||
$allowedTypes[] = GetMimeTypeOrExtension($value); | |||
} | |||
} else { | |||
echo json_encode(array( | |||
"code" => -1, | |||
"msg" => "未定义文件类型", | |||
"data" => null, | |||
)); | |||
exit; | |||
} | |||
$uploadedFile = $_FILES['file']['tmp_name']; | |||
$fileType = mime_content_type($uploadedFile); | |||
$imgSize = getimagesize($uploadedFile); | |||
if (!in_array($fileType, $allowedTypes) || !$imgSize) { | |||
if (!in_array($fileType, $allowedTypes)) { | |||
echo json_encode(array( | |||
"code" => -1, | |||
"msg" => "仅支持图片格式文件", | |||
"msg" => "当前文件格式不支持", | |||
"data" => null, | |||
)); | |||
exit; | |||
} | |||
//获取扩展名 | |||
$exts = GetMimeTypeOrExtension($fileType, 1); | |||
$width = 0; | |||
$height = 0; | |||
if ($mediatype === 1) { | |||
$imgSize = getimagesize($uploadedFile); | |||
if (!$imgSize) { | |||
echo json_encode(array( | |||
"code" => -1, | |||
"msg" => "无法获取当前图片正常尺寸", | |||
"data" => null, | |||
)); | |||
exit; | |||
} | |||
$width = $imgSize[0]; | |||
$height = $imgSize[1]; | |||
} | |||
if (!is_dir($cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}")) { | |||
MkdirAll($cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}", $cfg_dir_purview); | |||
CloseFtp(); | |||
} | |||
if ($type === "face") { | |||
//头像特殊处理 | |||
$target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/newface.png";//上传文件名 | |||
$target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/newface.png"; | |||
} else { | |||
$nowtme = time(); | |||
$rnd = $nowtme.'-'.mt_rand(1000,9999); | |||
$target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/".$rnd.".png"; | |||
$target_file = $cfg_basedir.$cfg_user_dir."/{$cfg_ml->M_ID}/".$rnd.".".$exts; | |||
$fsize = filesize($_FILES["file"]["tmp_name"]); | |||
$target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/".$rnd.".png"; | |||
$target_url = $cfg_mediasurl.'/userup'."/{$cfg_ml->M_ID}/".$rnd.".".$exts; | |||
$row = $dsql->GetOne("SELECT aid,title,url FROM `#@__uploads` WHERE url LIKE '$target_url' AND mid='".$cfg_ml->M_ID."'; "); | |||
$uptime = time(); | |||
if (is_array($row)) { | |||
$query = "UPDATE `#@__uploads` SET mediatype=1,width='{$imgSize[0]}',height='{$imgSize[1]}',filesize='{$fsize}',uptime='$uptime' WHERE aid='{$row['aid']}'; "; | |||
$query = "UPDATE `#@__uploads` SET mediatype={$mediatype},width='{$width}',height='{$height}',filesize='{$fsize}',uptime='$uptime' WHERE aid='{$row['aid']}'; "; | |||
$dsql->ExecuteNoneQuery($query); | |||
} else { | |||
$inquery = "INSERT INTO `#@__uploads`(url,mediatype,width,height,playtime,filesize,uptime,mid) VALUES ('$target_url','1','".$imgSize[0]."','".$imgSize[1]."','0','".$fsize."','$uptime','".$cfg_ml->M_ID."'); "; | |||
$inquery = "INSERT INTO `#@__uploads`(url,mediatype,width,height,playtime,filesize,uptime,mid) VALUES ('$target_url','$mediatype','".$width."','".$height."','0','".$fsize."','$uptime','".$cfg_ml->M_ID."'); "; | |||
$dsql->ExecuteNoneQuery($inquery); | |||
} | |||
} | |||
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) { | |||
require_once DEDEINC."/libraries/imageresize.class.php"; | |||
try{ | |||
$image = new ImageResize($target_file); | |||
if ($type === "face") { | |||
$image->crop(150, 150); | |||
} else { | |||
$image->resize($cfg_ddimg_width, $cfg_ddimg_height); | |||
if ($mediatype === 1) { | |||
//图片自动裁剪 | |||
require_once DEDEINC."/libraries/imageresize.class.php"; | |||
try{ | |||
$image = new ImageResize($target_file); | |||
if ($type === "face") { | |||
$image->crop(150, 150); | |||
} else { | |||
$image->resize($cfg_ddimg_width, $cfg_ddimg_height); | |||
} | |||
$image->save($target_file); | |||
echo json_encode(array( | |||
"code" => 0, | |||
"msg" => "上传成功", | |||
"data" => $target_url, | |||
)); | |||
} catch (ImageResizeException $e) { | |||
echo json_encode(array( | |||
"code" => -1, | |||
"msg" => "图片自动裁剪失败", | |||
"data" => null, | |||
)); | |||
} | |||
$image->save($target_file); | |||
} else { | |||
echo json_encode(array( | |||
"code" => 0, | |||
"msg" => "上传成功", | |||
"data" => $target_url, | |||
)); | |||
} catch (ImageResizeException $e) { | |||
echo json_encode(array( | |||
"code" => -1, | |||
"msg" => "图片自动裁剪失败", | |||
"data" => null, | |||
)); | |||
} | |||
} else { | |||
echo json_encode(array( | |||