Laravel How To Upload,View And Download Pdf,Docx,Mp4,Mp3 In Laravel Laravel Tutorial From Scratch

preview_player
Показать описание
In this tutorial you will learn about how you can upload any file in laravel and then how you can view them and download them as well.

I hope I was able to help you learn it.
Please make sure to subscribe to my channel. I will really appreciate it if you do and also give this video a like.

Support This Channel :

Join this channel to get access to perks:

Your support will be really appreciated.

Thanks For Watching.

I hope This video was helpful.

If you have any questions then let me know in the comment section.

Best of luck.

#webtechknowledge

You can connect with me with the given links below:

Join this channel to get access to perks:

Follow me on :
Рекомендации по теме
Комментарии
Автор

Source Code here


Controller

PageController.php




<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use



use App\Models\Product;




class PageController extends Controller
{
public function index()
{

return view('welcome');

}

public function uploadpage()
{

return view('product');

}

public function store(Request $request)
{

$data=new product();


$file=$request->file;



$request->file->move('assets', $filename);

$data->file=$filename;


$data->name=$request->name;


$data->save();
return redirect()->back();



}


public function show()
{

$data=product::all();
return view('showproduct', compact('data'));
}


public function download(Request $request, $file)
{


return
}



public function view($id)
{
$data=Product::find($id);

return view('viewproduct', compact('data'));


}








}






Models

Document.php



<?php

namespace App\Models;

use
use

class Document extends Model
{


use HasFactory;

protected $fillable=['name', 'description', 'file'];
}






Route
web.php




<?php

use

use





Route::get('/', [PageController::class, 'index']);

Route::get('/uploadpage', [PageController::class, 'uploadpage']);

Route::post('/uploadproduct', [PageController::class, 'store']);


Route::get('/show', [PageController::class, 'show']);

Route::get('/download/{file}', [PageController::class, 'download']);

Route::get('/view/{is}', [PageController::class, 'view']);













Views

product.blade.php



<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>


<form method="post"

@csrf

<input type="text" name="name" placeholder="Product Name">

<input type="text" name="description" placeholder="Product description">

<input type="file" name="file">

<input type="submit" >


</form>

</body>
</html>






showproduct.blade.php





<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<table border="1px">

<tr>
<th>Name</th>
<th>Description</th>
<th>View</th>
<th>Download</th>
</tr>

@foreach($data as $data)

<tr>
<td>{{$data->name}}</td>

<td><a href="{{url('/view', $data->id)}}">View</a></td>
<td><a href="{{url('/download', $data->file)}}">Download</a></td>


</tr>




@endforeach

</table>

</body>
</html>






viewproduct.blade.php



<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>


{{$data->name}}
{{$data->description}}

<iframe height="400" width="400"

</body>
</html>






welcome.blade.php





</div>


<h1>Welcome to Laravel Tutorial</h1>
<div>
<h2>How To Upload, View, Download Pdf, Docx, Video, Mp3 In Laravel</h2>
</div>


<a class="btn btn-success" Page</a>


</div>

WebTechKnowledge
Автор

I have watched dozens of tutorials trying to display a pdf file in an iframe element and it wasn't working. All of a sudden I watch this video and it works! And the crazy thing about it is that you did not change anything, it's the same as the others🙆‍♂🙆‍♂🙆‍♂

new_direction_net
Автор

You saved a brothers life bro, all other tuts were complicating a rather easy piece of code

kamauseffu
Автор

Thanks again sir, aaaa masyaaAllah ❤ the tutorial simple and there is no problem 👍🏻✨

Nisaa_
Автор

Thank you for video, i had seen this video and i solved one problem

ImranShaikh-luwq
Автор

Very good ! Extremely helpful, thanks !

fernandafratamamud
Автор

This is a very recommended video for view and download file good job sir! 👍

name_code
Автор

Simple and understandable explanation. Thanks a lot!

oleksandraromanova
Автор

Thanks sir for this simple code. Now I Have exactly like in this video but my file isn't downloading / viewing. I realized that you typed the name storage wrongly when calling the illuminate.... and yours worked. Could you please give a solution to make the file downloadable

englishprimiereleague
Автор

It's awesome and appreciated, would be great if you share source code link :)

Muhammadijaz-pttd
Автор

i am facing 404 not found.My File is successfully uploaded in db and in location also but not showing in iframe, , , i use move(public_path('images') instead of storage. Pls help i am stuck

shailzarani
Автор

Thank you so much, it worked fine with me at laravel" ^8.12" 😍

sawsanaljuhani
Автор

Thank you so much sir, but I have a question why only pdf, photos and videos can be seen in view. like docx, excel can't be seen in view, it downloads automatically.

fajardwirani
Автор

Sir can we upload and view the pdf video documents file threw ajax. If its possible then please one video where help of ajax video pdf file will upload. Its request sir

lucifer
Автор

I get this error "Call to undefined method

melodicTune
Автор

Route::get('/view/{is}', [PageController::class, 'view']); if i have to file in which i use view how i can differentiate it

dbetynl
Автор

The upload works fine and files are uploaded in assets folder and the View worked fine, but still download Show The GET method is not supported for this route. Supported methods: POST. what can i do

e-learningedu
Автор

I thought you use instead of But why still not facing an error?

ALEXANDERUJANG
Автор

Hip picure a situation where i only want to preview part of the file (eg only page one). How do i approach that

davidkamau
Автор

Nice, but show how to do file validation, extentions and size, for video not more then 400mb and etc.

konstantinnefedov