'Local', 2 => 'Qiniu', 3 => 'Oss', ); public function getUrl($info) { if (strstr($info['file'], 'http')) { return $info['file']; } $save = Dever::db('save', 'upload')->find($info['save_id']); if ($save['host']) { $host = $save['host']; if (strstr($host, '{host}')) { $host = str_replace('{host}', Dever::host(), $host); } } else { $host = Dever::host() . 'data/' . DEVER_PROJECT . '/upload/'; } return $host . $info['file']; } public function local($file) { $host = Dever::host() . 'data/'; if (strstr($file, $host)) { return str_replace($host, Dever::data(), $file); } else { $local = Dever::file('tmp/' . md5($file)); file_put_contents($local, file_get_contents($file), LOCK_EX); return $local; } } public function http($file) { $base = Dever::data(); $host = Dever::host() . 'data/'; if (strstr($file, $base)) { return str_replace($base, $host, $file); } else { $local = Dever::file('tmp/' . md5($file)); file_put_contents($local, file_get_contents($file), LOCK_EX); return str_replace($base, $host, $local); } } # 从内容中解析文件 public function file($content, $domain, $local = false) { $content = preg_replace_callback('/[0-9a-zA-Z\-\\/]+(\.jpeg|\.jpg|\.png|\.gif|\.mp3|\.mp4|\.aov|\.m4a)/i', function($matches) use($domain, $local) { $file = $matches[0]; $file = ltrim($file, '/'); if (!strstr($file, 'http')) { $file = $domain . $file; } if ($local) { $upload = Dever::load('save', 'upload')->act($local, $file); if ($upload && isset($upload['url'])) { $file = $upload['url']; } } return $file; }, $content); return $content; } }