File Upload in Laravel: Main Things You Need To Know

preview_player
Показать описание
I see many beginners have trouble understanding terms like "disks", "drivers", "storage", and "filesystem". So, I tried to shoot this "step-by-step summary" with a demo project.

00:00 Intro
00:51 Simple File Upload
02:06 Disks: Public vs Local
04:10 Show Public Files
05:04 Download Private Files
06:29 Encoded Filenames
08:01 Subfolders VS Disks
10:02 No storage:link?
10:53 Spatie Media Library
12:30 Amazon S3 Disk

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

Excellent explanation.Spartie media library solves many problems as you mentioned.

hassanfazeel
Автор

Thank you.I just got a deep understanding of the disks.But I have a different method of having a class ie ImageProcessor which I use for all my image processing.

evanceodhiambo
Автор

I think your explanation way suite just the master developer

ABEDALLAHGOZAH
Автор

Very well explained, at 12:09, you missed to explain how to download private files when using Spatie Media library, It works for public but 404 for private files while downloading.

aliaxonbaig
Автор

Thank you sir great mentor, You really kill it for storage tutorial.

techfuture-code-tv
Автор

Thanks for the video.

Those who don't have SSH access can create a route to generate symlink.

Route::get(
'symlink',
fn () => Artisan::call(
'storage:link'
)
);

will generate the link.

bulent
Автор

Just btw, the s3 filesystem does also support `root`, so you can do the same "make a new disk per thing to store" and use a single s3 bucket for public and a single buckeet for private

JohnRoux
Автор

I've been waiting for this amazing video! Thank you Povilas! More one great content, very clear explanation!

pebarradas
Автор

Good one! At @9:43 shouldn't you change the public to avatars in the disk method?

SaiyanJin
Автор

Thank you very much for your helpful videos, master. This is one of the treasures.

roman_zabigaliuk
Автор

I don't use file as an extra field in the db table, instead have a separate controller and model for cv, and avatar, that is an Avatar controller and a CV controller. I then use the post controller to handle both file inputs. I take the post ID after the post has been updated and save it
if ($file = $request->file('CVfile')) {

if (CVFilecontroller::where('post_id', '=', $request->post_id)) {
$jobfiler = JobOpslagFile::all()->where("post_id", $id);
foreach($jobfiles as $CVfile){
$filename = $CVfile->name;
$CVfile->delete();
$CVfile_path =

unlink($CVfile_path);
}
}
}

$fileName = "CVfile".auth()->id() . '_' . time() . '.'.

$type =
$size = $request->CVfile->getSize();

$request->CVfile->move(public_path('CVfile'), $fileName);

CVFilecontroller::create([
'user_id' => auth()->id(),
'post_id' => $id,
'name' => $fileName,
'type' => $type,
'size' => $size
]);
}

FririkurEllefsen
Автор

awesome information as always. thanks 👍

raj-kal
Автор

Hi,
Awesoem tutorial as always.

I have a question, in the case of private file, you told the method to allow "Download" the file, what if we want to show the image (to only authorized users)?

waheed
Автор

Thank you for this video. I want to store some user files in private disk but i want to let only user view their own files in browser because if i put them in public and any user gets the name they can view it. can you help this?

bood_kr
Автор

Thank you!

Please tell me how you can set up folders for the Spatie media library so that if there are a large number of files, they can be sorted into subfolders? and is it possible not to do a subscription for one file?

QuotesGT
Автор

Is it possible get a url for a private (just authenticated) file? For example, for load image in some <image src="...">

alonsoramirezpaez
Автор

Terrific tutorial --- thanks! Why are the methods getClientOriginalName and getClientOriginalExtension "considered unsafe"? The Laravel docs says it's because "the file name and extension may be tampered with by a malicious user". What kind of "tampering" is possible and what could the effect of such tampering be? Is it unsafe even to get that information and store it in the database as a field (without using it as the name of the file)?

martin.j.osborne
Автор

You rock!!!

How can we crop avatar image to store small and centered images?

luispointme
Автор

Great tips as always! May I ask what app are you using to connect to the database? Thank you

alex_nita
Автор

If Spatie Media Library can move files from storage to public folder, does that mean that you don't need the sym link?

l.b