各位大佬,在將項目打包為bin文件后,原系統(tǒng)里有個從public目錄里獲取字體文件生成驗證碼的功能,打包成bin后,系統(tǒng)提示無法獲取到文件,且打包配置文件里的 exclude_pattern 也沒有排除 public目錄,請問這個還會是什么情況導(dǎo)致
錯誤內(nèi)容:
getimagesize(phar:\D:\MyProject\admin\build\admin.phar\public\static\fonts\sai.ttf): Failed to open stream: No such file or directory
/**
* @param $font
* @return string
*/
protected static function getFontPath($font)
{
static $fontPathMap = [];
if (!\class_exists(\Phar::class, false) || !\Phar::running()) {
return $font;
}
$tmpPath = sys_get_temp_dir() ?: '/tmp';
$filePath = "$tmpPath/" . basename($font);
clearstatcache();
if (!isset($fontPathMap[$font]) || !is_file($filePath)) {
file_put_contents($filePath, file_get_contents($font));
$fontPathMap[$font] = $filePath;
}
return $fontPathMap[$font];
}
$fontttf = self::getFontPath($ttfPath . $config['fontttf']);
我用的那個tinywang的驗證碼插件 應(yīng)該是同理的,解決方法抄的webman作者出的那個驗證碼,目前已解決
可以,這個方案可行,其實文件還是獲取的二進制文件外的字體文件了,可以將那個臨時目錄改寫入到 runtime目錄里去,就在當前運行程序下的runtime目錄里了,不會到系統(tǒng)緩存目錄里了