打包后,修改用戶頭像 拋出
Can't write image data to path (phar:///www/wwwroot/webman_pack/build/webman.phar/plugin/admin/public/upload/avatar/202405/663dc6f47d0b.lg.jpg)
根據(jù)打包文檔配置 http://m.wtbis.cn/doc/webman/others/phar.html
1.config/plugin/webman/console/app.php 配置
'exclude_pattern' => '#^(?!.*(composer.json|/.github/|/.idea/|/.git/|/.setting/|/runtime/|/vendor-bin/|/build/|vendor/webman/admin))(.*)$#'
config/app.php配置
'public_path' => base_path(false) . DIRECTORY_SEPARATOR . 'public',
1.修改插件內(nèi)的上傳頭像源碼,重新打包,再上傳頭像提示
刪除了/plugin/admin/ 拼接
提示 Can’t write image data to path (phar:///www/wwwroot/webman_pack/webman.phar/public/upload/avatar/202405/663dd032ca59.lg.png)
2.帖子 http://m.wtbis.cn/q/8086 根據(jù)老大提供的方法改了,也提示上傳路徑有誤
備注:文件給了777權(quán)限
1.照文檔配置更改 http://m.wtbis.cn/doc/webman/others/phar.html
2.更改后臺(tái)插件上傳頭像配置(其他上傳自行測(cè)試)路徑為 項(xiàng)目根目錄/plugin/admin/app/controller/UploadController.php/avatar
/**
* 上傳頭像
* @param Request $request
* @return Response
* @throws Exception
*/
public function avatar(Request $request): Response
{
$file = current($request->file());
if ($file && $file->isValid()) {
$ext = strtolower($file->getUploadExtension());
if (!in_array($ext, ['jpg', 'jpeg', 'gif', 'png'])) {
return json(['code' => 2, 'msg' => '僅支持 jpg jpeg gif png格式']);
}
$image = Image::make($file);
$width = $image->width();
$height = $image->height();
$size = min($width, $height);
$relative_path = 'upload/avatar/' . date('Ym');
$real_path = "./public/$relative_path";//這個(gè)是上傳路徑更改
print_r($real_path);
if (!is_dir($real_path)) {
mkdir($real_path, 0777, true);
}
$name = bin2hex(pack('Nn',time(), random_int(1, 65535)));
$ext = $file->getUploadExtension();
$image->crop($size, $size)->resize(300, 300);
$path = "./public/$relative_path/$name.lg.$ext";//這個(gè)是上傳路徑更改
$image->save($path);
$image->resize(120, 120);
$path = "./public/$relative_path/$name.md.$ext";//這個(gè)是上傳路徑更改
$image->save($path);
$image->resize(60, 60);
$path = "./public/$relative_path/$name.$ext";//這個(gè)是上傳路徑更改
$image->save($path);
$image->resize(30, 30);
$path = "./public/$relative_path/$name.sm.$ext";//這個(gè)是上傳路徑更改
$image->save($path);
return json([
'code' => 0,
'msg' => '上傳成功',
'data' => [
'url' => "/public/$relative_path/$name.$ext" //這個(gè)是上傳后回顯的路徑
]
]);
}
return json(['code' => 1, 'msg' => 'file not found']);
}
1.我的打包命令為(項(xiàng)目根目錄) php -d phar.readonly=0 ./webman build:phar
2.如果更新插件官方后臺(tái),則會(huì)覆蓋當(dāng)前修改的代碼,切記
你試試
\Phar::running() ? pathinfo(\Phar::running(false), PATHINFO_DIRNAME) . '/public' : realpath(base_path() . '/../public');
我這兩天在做圖片上傳也遇到這個(gè)問題了,我是使用的use Intervention\Image\ImageManagerStatic庫(kù)對(duì)圖片進(jìn)行壓縮處理然后調(diào)用保存也出現(xiàn)了Intervention\Image\Exception\NotWritableException: Can't write image data to path報(bào)錯(cuò),但是測(cè)試用webman的move方法保存就不會(huì)出錯(cuò),保存的路徑都是相同的,最后的結(jié)局方案就是,輸出圖片二進(jìn)制數(shù)據(jù)然后用 file_put_contents保存