//-------- サービス
// mime-typeの決定
-function attach_mime_content_type($filename)
+function attach_mime_content_type($filename, $displayname)
{
$type = 'application/octet-stream'; // default
if (! file_exists($filename)) return $type;
-
- $size = @getimagesize($filename);
- if (is_array($size)) {
- switch ($size[2]) {
- case 1: return 'image/gif';
- case 2: return 'image/jpeg';
- case 3: return 'image/png';
- case 4: return 'application/x-shockwave-flash';
+ $pathinfo = pathinfo($displayname);
+ $ext0 = $pathinfo['extension'];
+ if (preg_match('/^(gif|jpg|jpeg|png|swf)$/i', $ext0)) {
+ $size = @getimagesize($filename);
+ if (is_array($size)) {
+ switch ($size[2]) {
+ case 1: return 'image/gif';
+ case 2: return 'image/jpeg';
+ case 3: return 'image/png';
+ case 4: return 'application/x-shockwave-flash';
+ }
}
}
-
- $matches = array();
- if (! preg_match('/_((?:[0-9A-F]{2})+)(?:\.\d+)?$/', $filename, $matches))
- return $type;
-
- $filename = decode($matches[1]);
-
// mime-type一覧表を取得
$config = new Config(PLUGIN_ATTACH_CONFIG_PAGE_MIME);
$table = $config->read() ? $config->get('mime-type') : array();
unset($config); // メモリ節約
-
foreach ($table as $row) {
$_type = trim($row[0]);
$exts = preg_split('/\s+|,/', trim($row[1]), -1, PREG_SPLIT_NO_EMPTY);
foreach ($exts as $ext) {
- if (preg_match("/\.$ext$/i", $filename)) return $_type;
+ if (preg_match("/\.$ext$/i", $displayname)) return $_type;
}
}
-
return $type;
}
$this->time_str = get_date('Y/m/d H:i:s', $this->time);
$this->size = filesize($this->filename);
$this->size_str = sprintf('%01.1f', round($this->size/1024, 1)) . 'KB';
- $this->type = attach_mime_content_type($this->filename);
+ $this->type = attach_mime_content_type($this->filename, $this->file);
return TRUE;
}
/////////////////////////////////////////////////
// Image suffixes allowed
-define('PLUGIN_REF_IMAGE', '/\.(gif|png|jpe?g)$/i');
+define('PLUGIN_REF_IMAGE', '/\.(gif|png|jpe?g|swf)$/i');
// Usage (a part of)
define('PLUGIN_REF_USAGE', "([pagename/]attached-file-name[,parameters, ... ][,title])");
if(! file_exists($ref))
return array('msg'=>'Attach file not found', 'body'=>$usage);
+ $is_image = preg_match(PLUGIN_REF_IMAGE, $filename);
+ if (!$is_image) {
+ return array('msg'=>'Seems not an image', 'body'=>$usage);
+ }
$got = @getimagesize($ref);
if (! isset($got[2])) $got[2] = FALSE;
switch ($got[2]) {