Skip to content

Commit

Permalink
尝试修复 typecho#168
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Jan 11, 2014
1 parent 787c143 commit db3bfaa
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions var/Widget/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ private static function makeUploadDir($path)
* @access private
* @return string
*/
private static function getSafeName($name)
private static function getSafeName(&$name)
{
preg_split("/(\/|\\\|:)/"
$name = str_replace('\\', '/', $name);
$name = false === strpos($name, '/') ? ('a' . $name) : str_replace('/', '/a', $name);
$info = pathinfo($name);
$name = substr($info['basename'], 1);

return isset($info['extension']) ? $info['extension'] : '';
}

/**
Expand All @@ -85,14 +90,7 @@ public static function uploadHandle($file)
return $result;
}

$file['name'] = basename($file['name']);

//获取扩展名
$ext = '';
$part = explode('.', $file['name']);
if (($length = count($part)) > 1) {
$ext = strtolower($part[$length - 1]);
}
$ext = self::getSafeName($file['name']);

if (!self::checkFileType($ext)) {
return false;
Expand Down Expand Up @@ -164,15 +162,8 @@ public static function modifyHandle($content, $file)
return $result;
}

$file['name'] = basename($file['name']);
$ext = self::getSafeName($file['name']);

//获取扩展名
$ext = '';
$part = explode('.', $file['name']);
if (($length = count($part)) > 1) {
$ext = strtolower($part[$length - 1]);
}

if ($content['attachment']->type != $ext) {
return false;
}
Expand Down

0 comments on commit db3bfaa

Please sign in to comment.