File Upload in Laravel: Main Things You Need To Know

File Upload in Laravel: Main Things You Need To Know

Laravel Daily

7 месяцев назад

20,101 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Ikram Khizer
Ikram Khizer - 11.11.2023 12:02

"??=" What does that syntax mean? It's not Null coalescing

Ответить
Vivek Ghongate
Vivek Ghongate - 04.11.2023 18:39

Thank you for explain is easy way

Ответить
Gergely Csermely
Gergely Csermely - 01.11.2023 13:29

Thanks

Ответить
ABEDALLAH GOZAH
ABEDALLAH GOZAH - 26.10.2023 16:01

I think your explanation way suite just the master developer

Ответить
EVANCE ODHIAMBO
EVANCE ODHIAMBO - 26.10.2023 09:22

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.

Ответить
Alexandr Nita
Alexandr Nita - 24.10.2023 09:31

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

Ответить
Obed Dougan
Obed Dougan - 22.10.2023 11:42

What about Google drive??

Ответить
Hassan Fazeel
Hassan Fazeel - 21.10.2023 18:18

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

Ответить
Shaikh Foysal
Shaikh Foysal - 21.10.2023 05:56

Thanks so helpful video. Thanks

Ответить
Alexmitico
Alexmitico - 20.10.2023 21:56

Why you save in the variable $avatar the action Storage::disk.... Why you dont simple do Storage::disk... without saving in $avatar that is something that I saw also in real life projects but I never understand why

Ответить
Nika Simonishvili
Nika Simonishvili - 20.10.2023 10:02

What ??= operator does?

Ответить
Fríðrikur Ellefsen
Fríðrikur Ellefsen - 19.10.2023 19:12

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 = public_path('ansfil/'.$filename);
if(file_exists($CVfile_path)){
unlink($CVfile_path);
}
}
}

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

$type = $request->CVfile->getClientMimeType();
$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
]);
}

Ответить
AZ DAVAI
AZ DAVAI - 19.10.2023 12:46

This is ressourceful

Ответить
Martin J. Osborne
Martin J. Osborne - 19.10.2023 05:35

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)?

Ответить
k0wu
k0wu - 18.10.2023 22:38

i have last_login_at column in table users. how update this column when user logs in? event listener doesnt work...

Ответить
Quotes GT
Quotes GT - 18.10.2023 19:43

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?

Ответить
amir kouchaki
amir kouchaki - 18.10.2023 15:46

When trying to create a user page in which the posts can only be seen by the followers of the page and the owner themself, where should I store the posts images? If I store it in the public disk anyone that has gotten the image link once can access it forever. Is this a problem? For example what would a platform like instagram do for private pages and the images in those pages?

Ответить
abdul waheed
abdul waheed - 18.10.2023 15:23

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)?

Ответить
Raj Choudhary
Raj Choudhary - 18.10.2023 14:54

awesome information as always. thanks 👍

Ответить
Fuskydon
Fuskydon - 18.10.2023 14:15

Please @LaravelDaily, can you help us create a video on Localisation. Am trying to build a Laravel Application of English and Arabic, many Laravel developers are having this issue also and also the use of rtl & ltr when chnaging from Arabic to English, can you help with this Sir?

For todays tutroial, i really do learn a lot, Thanks 👍

Ответить
Роман Забигалюк
Роман Забигалюк - 18.10.2023 12:15

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

Ответить
John Roux
John Roux - 18.10.2023 10:55

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

Ответить
Bülent
Bülent - 18.10.2023 10:48

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.

Ответить
Sahil Kumar
Sahil Kumar - 18.10.2023 10:48

Hello sir,

How to upload a zip file which contains some xls files inside.
So basically upload zip file then extract it somewhere and start inserting all rows of each xls files into database.

Ответить
Dylan Dile
Dylan Dile - 18.10.2023 10:34

Ho about file size configurations? For both the Laravel Application and the web server you are using.

Ответить
Mimis K
Mimis K - 18.10.2023 10:00

So we can use spatie/media-library for any file type? 🤔

Ответить
David labadze
David labadze - 18.10.2023 09:38

Ответить
Sandeep Bhambre
Sandeep Bhambre - 18.10.2023 09:16

What about file visibility?

Ответить
Michael Nwogu
Michael Nwogu - 18.10.2023 09:02

I don't really know how laravel handles caches

Ответить
Shayan's Code Community
Shayan's Code Community - 18.10.2023 08:16

Sir which cache driver should I use in Laravel? Please tell me sir.

Ответить
Luis Alberto Oliveira
Luis Alberto Oliveira - 18.10.2023 08:02

You rock!!!

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

Ответить