控制器:
public function index()
{
if (!file_exists("uploads/profiles/".\Auth::User()->id.".jpeg")) {
$image_content = File::get("uploads/profiles/default.jpg");
$image = response($image_content, 200)->header('Content-Type', 'image/jpeg');
$size = getimagesize($image);
$aspectratio = $size[0]/$size[1];
$img_thumbnail = Image::make($image)->resize(50*$aspectratio,50);
$img_profile = Image::make($image)->resize(160*$aspectratio,160);
$imgname = \Auth::User()->id;
$img_thumbnail->save('uploads/thumbnails/'.$imgname.".jpeg");
$img_profile->save('uploads/profiles/'.$imgname.".jpeg");
}
错误::无法打开流:没有此类文件或目录。
实际上,我想获取default.jpg图像并将其保存到另外两个具有不同扩展名的文件夹中。
答案 0 :(得分:1)
if( !file_exists('uploads/thumbnails/'. $folder)){
@mkdir('uploads/thumbnails/'. $folder, 0755);
}
if( !file_exists('uploads/profiles/'. $folder)){
@mkdir('uploads/profiles/'. $folder, 0755);
}
$img = 'uploads/profiles/'. \Auth::User()->id. '.jpeg';
if ( !file_exists($img)){
$save_extension = '.jpeg';
Image::make($img)
->resize(50, null, function ($constraint) {
$constraint->aspectRatio();
})->save('uploads/thumbnails/' . \Auth::User()->id . $save_extension);
Image::make($img)
->resize(160, null, function ($constraint) {
$constraint->aspectRatio();
})->save('uploads/profiles/' . \Auth::User()->id . $save_extension);
}
答案 1 :(得分:0)
public function index()
{
if (!file_exists("uploads/profiles/".\Auth::User()->id.".jpeg")) {
$image = File::get("uploads/profiles/default.jpg");
return response($image)->header('Content-Type', 'image/jpeg');
}
答案 2 :(得分:0)
确保您拥有uploads/profiles/
chmod -R 777 /uploads/profiles/