Laravel Tutorials
- What is laravel
- Laravel Installation
- Directory Structure
- htaccess
- Remove public from url
- Artisan Command
- Laravel Configuration
- Routing Configuration
- Namespaces
- Request
- Response
- Controller
- Model
- User Authentication
- Multi User Authentication
- Database Seeding
- Database
- Database Query
- ORM
- One-to-One Relationship
- One-to-Many Relationship
- Many to Many Eloquent Relationship
- Has One Through
- Has Many Through
- Querying Relations
- Middleware
- Laravel Views
- Blade Views
- Print data on view page
- Get Site URL
- Get URL Segment
- Get images from Storage folder
- Clear cache
- Form Class not found
- Flash Message in laravel
- Redirections
- path
- CRUD Projerct
- CRUD in Laravel
- CRUD progran
- Laravel Validation
- Jquery Validation
- Cookie
- Session
- Email Send in laravel
- File uploading
- CSRF Protection
- Helper in Laravel
- Helper Functions
- Guzzle Http Client
- Paypal Payment Gatway Integration
- Cron Job in laravel
- Flash message
- path
- Errors Handling
- Date Format
- Date Format Validation
- Display Image on View Page
- Update User Status using toggle button
- Delete Multiple Records using Checkbox in Laravel?
- Confirmation Before Delete Record
- Delete image from storage
- Remove/Trim Empty & Whitespace From Input Requests
- Block IP Addresses from Accessing Website
- How to Disable New User Registration in Laravel
- Redirect HTTP To HTTPS Using Laravel Middleware
- CKEditor
- slug generate unique
- Prevent Browser's Back Button After Logout
- Datatable dunamically
- encrypt & Decript
- Download File
- Rest API
- Shopping Cart
- Shopping Cart Example
- Dynamic Category-Subcategory Menu
- Ajax Search
- Interview Question
- laravel Tutorilal link
- laravel Tutorilal
Important Links
What is File uploading in laravel?
View page
@if(count($errors)>0)
<div class="alert alert-danger">
<p>Upload Validation Error</p><br/><br/>
@foreach($errors->all() as $er)
<li>{{$er}}</li>
@endforeach
</div>
@endif
@if(session('success'))
<h3>{{session('success')}}</h3>
@endif
{{--
@if($message == Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">x</button>
<strong>{{ $message }}</strong>
</div>
<img src="/images/{{Session::get('path')}}" width="300" height="300"/>
@endif
--}}
<form name="frm" action="{{url('data_upload')}}" method="post" enctype="multipart/form-data">
@csrf
<div>
<input type="file" id="profileimage" name="profileimage">
</div>
<br/>
<button type="submit" class="btn btn-primary" style="float:right;">Submit</button>
</form>
File name : controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UploadData extends Controller
{
public function index()
{
return view('imageupload');
}
public function uploadfile(Request $request)
{
$this->validate($request,['profileimage'=>'required|image|mimes:jpeg,png,jpg,gif|max:2048']);
$image = $request->file('profileimage');
$new_name = random_int(1,9999).'.'.$image->getClientOriginalExtension();
//$image->move(public_path('logo'),$new_name);
$uploaded_path = public_path('images');
$image->move($uploaded_path,$new_name);
return back()->with('success','images upload successfully')->with('image',$new_name);;
}
}
How to upload file in laravel
File name : index.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class UploadFileController extends Controller {
public function index() {
return view('uploadfile');
}
public function showUploadFile(Request $request) {
$file = $request->file('image');
//Display File Name
echo 'File Name: '.$file->getClientOriginalName();
echo '<br>';
//Display File Extension
echo 'File Extension: '.$file->getClientOriginalExtension();
echo '<br>';
//Display File Real Path
echo 'File Real Path: '.$file->getRealPath();
echo '<br>';
//Display File Size
echo 'File Size: '.$file->getSize();
echo '<br>';
//Display File Mime Type
echo 'File Mime Type: '.$file->getMimeType();
//Move Uploaded File
$destinationPath = 'uploads';
$file->move($destinationPath,$file->getClientOriginalName());
}
}
Route File
File name : index.php
Route::get('/uploadfile','UploadFileController@index');
Route::post('/uploadfile','UploadFileController@showUploadFile');
How to check File exist or not?
if(file_exists(public_path('images/mahi.jpg'))){
dd('File is exists.');
}else{
dd('File is not exists.');
}
if(File::exists(public_path('images/nusrat.jpg'))){
dd('File is exists.');
}else{
dd('File is not exists.');
}
How to check file exist or Not
File name : index.php
public function index()
{
if (Storage::exists(public_path('img/dummy.jpg'))) {
dd('File is Exists');
}else{
dd('File is Not Exists');
}
}
File name : index.php
File name : index.php
File name : index.php
File name : index.php
File name : index.php
File name : index.php
File name : index.php