0% found this document useful (0 votes)
5 views1 page

If ($Request-hasFile('Student Image

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

If ($Request-hasFile('Student Image

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

if ($request->hasFile('student_image')) {

$request->validate([
"student_image" => 'mimes:jpeg,png,bmp,tiff|max:4096'
]);

$filenameWithExtension = $request->file("student_image");

// Get the filename without the extension


$filename = pathinfo($filenameWithExtension, PATHINFO_FILENAME);
// Get the file extension
$extension = $request->file("student_image")-
>getClientOriginalExtension();

// Create a unique filename to store


$filenameToStore = $filename . '_' . time() . '.' . $extension;
$smallThumbnail = $filename . '_' . time() . '.' . $extension;

$request->file('student_image')->storeAs('public/student',
$filenameToStore);
$request->file("student_image")->storeAs('public/student/thumbnail',
$smallThumbnail);

// Corrected path for thumbnail


$thumbnail = 'storage/student/thumbnail/' . $smallThumbnail;

// Create thumbnail
$this->createThumbnail($thumbnail, 150, 93);

$validated['student_image'] = $filenameToStore;
}

$student->update($validated); // Update the student


return back()->with('message', 'Data was successfully updated'); //
Redirect with success message
}

You might also like