Level 88
What is returning null? Can you be more specific?
1 like
So I have a form on local dev where I can upload images and it works.. but when I uploaded it on my web server. It doesn't seem to work. I mean, the form is working but It's returning null.
What is returning null? Can you be more specific?
@bobbybouwmann Either request file for avatar or cover returns null when I try to dd. I don't know what's wrong 'cuz it's working fine on my dev machine.
$reqAvatar = $request->file('avatar');
$reqCover = $request->file('cover');
if ($request->hasFile('avatar') && $reqAvatar->isValid()) {
$avatarFileExt = $reqAvatar->getClientOriginalExtension();
$avatar = str_random(10).'_'.time().'.'.$avatarFileExt;
$image = Image::make($reqAvatar);
$image->backup();
$image->fit(100);
$image->save('images/avatars/thumb/'.$avatar);
$image->reset();
$image->fit(800, 600, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$image->save('images/avatars/'.$avatar);
Auth::user()->update(['avatar' => $avatar]);
$returnPATH = asset('images/avatars/thumb/'.Auth::user()->avatar);
$message = 'Your avatar has been successfully changed.';
return response()->json([
'path' => $returnPATH,
'message' => "<strong class='text-success'>Great!</strong> ".$message,
], 200);
}
if ($request->hasFile('cover') && $reqCover->isValid()) {
$coverFileExt = $reqCover->getClientOriginalExtension();
$cover = str_random(10).'_'.time().'.'.$coverFileExt;
$image = Image::make($request->file('cover'))->encode('jpg', 50);
$image->backup();
$image->resize(null, 460, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$image->save('images/cover/thumb/'.$cover, 50);
$image->reset();
$image->resize(null, 460, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$image->save('images/cover/'.$cover);
Auth::user()->update(['cover' => $cover]);
$returnPATH = asset('images/cover/thumb/'.Auth::user()->$cover);
$message = 'Your cover photo has been successfully changed.';
return response()->json([
'path' => $returnPATH,
'message' => "<strong class='text-success'>Great!</strong> ".$message,
], 200);
}
It's probably permission issue, check that you image folder is writable
@alenn Thank you for asking but I think that's not the case because I also have another form that does the same. Except this method is post. By the way the one above uses patch and sent via ajax.
Please or to participate in this conversation.