Level 67
$filename = time() . '.' . $image;
What does that come out to? $image is the image object that you got from the request in the line above it, not the name of the image...
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I'm trying to store images to the public folder, but it's telling me that I can't write image data to path. Please help! Here is my code:
if (request()->hasFile('image')) {
$image = request()->file('image');
$filename = time() . '.' . $image;
$path = public_path('images/' . $filename);
// if (!file_exists($path)) {
// mkdir($path, 666, true);
// }
Image::make($image)->resize(128, 128)->encode('jpg', 75)->save($path);
Election::create([
'image' => $filename
]);
}
I have tried to do chmod -R 777 public/images/ but that doesn't work
Please or to participate in this conversation.