Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

Laravel File Upload Progress Bar Example Tutorial

Today, We want to share with you Laravel File Upload Progress Bar Example Tutorial From Scratch.In this post we will show you Laravel Ajax File Upload Progress Bar, hear for Laravel File Upload Progress Bar Meter Tutorial Ajax we will give you demo and example for implement.In this post, we will learn about Ajax File Upload with Progress Bar using Laravel JQuery with an example.

Laravel File Upload Progress Bar Example Tutorial From Scratch

There are the Following The simple About Laravel File Upload Progress Bar Example Tutorial From Scratch Full Information With Example and source code.

  jQuery AJAX laravel 6 Delete Data from database

As I will cover this Post with live Working example to develop Laravel Progress Bar for PHP AJAX File Upload, so the some PHP Laravel File Upload with Progress Bar for this example is following below.

Step 1: Create Routes

PHP Laravel File Upload with Progress Bar in Laravel Route, Model and Controller.

routes/web.php

Route::get('live-img-file-upload-example', '[email protected]');
Route::post('live-img-file-upload-example', '[email protected]')->name('imgfileUploadPost');

Step 2: Make a Laravel imgfluploadController

app/Http/Controllers/imgfileUploadPost.php

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
class imgfluploadController extends Controller
{
    public function imgfileUpload()
    {
    	return view('imgfileUpload');
    }

    public function imgfileUploadPost(Request $request)
    {
        $request->validate([
            'file' => 'required',
		]);

        $imgflName = time().'.'.request()->file->getClientOriginalExtension();
        request()->file->move(public_path('files'), $imgflName);
        return response()->json(['success'=>'Good Luck, You have 100% successfully All files or images uploaded.']);
    }
}

Step 3: Make a Laravel Blade File

resources/views/imgfileUpload.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel File Upload Progress Bar Example Tutorial From Scratch - pakainfo.com</title>
    <link rel="stylesheet" href="bootstrap/4.1.3/css/bootstrap.min.css">
    <style>
        .progress { position:relative; width:100%; border: 1px solid #7F98B2; padding: 1px; border-radius: 3px; }
        .bar { background-color: #B4F5B4; width:0%; height:25px; border-radius: 3px; }
        .percent { position:absolute; display:inline-block; top:3px; left:48%; color: #7F98B2;}
    </style>
</head>
<body>

<div class="pakainfo container">
    <div class="pakainfo card">
      <div class="pakainfo card-header">
        <h2>Laravel 5.6 - File upload with progress bar - pakainfo.com</h2>
      </div>
      <div class="pakainfo card-body">
            <form method="POST" action="{{ route('imgfileUploadPost') }}" enctype="multipart/form-data">
                @csrf
                <div class="gst form-group">
                    <input name="file" id="poster" type="file" class="form-control"><br/>
                    <div class="progress">
                        <div class="bar"></div >
                        <div class="percent">0%</div >
                    </div>
                    <input type="submit"  value="Submit" class="btn btn-success">
                </div>
            </form>
      </div>
    </div>
</div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="//malsup.github.com/jquery.form.js"></script>

<script type="text/javascript">

    function validate(formData, jqForm, options) {
        var form = jqForm[0];
        if (!form.file.value) {
            alert('File not found');
            return false;
        }
    }

    (function() {

    var bar = $('.bar');
    var percent = $('.percent');
    var status = $('#status');

    $('form').ajaxForm({
        beforeSubmit: validate,
        beforeSend: function() {
            status.empty();
            var totalValPercentage = '0%';
            var posterValue = $('input[name=file]').fieldValue();
            bar.width(totalValPercentage)
            percent.html(totalValPercentage);
        },
        uploadProgress: function(event, position, total, percentComplete) {
            var totalValPercentage = percentComplete + '%';
            bar.width(totalValPercentage)
            percent.html(totalValPercentage);
        },
        success: function() {
            var totalValPercentage = 'Wait, Saving';
            bar.width(totalValPercentage)
            percent.html(totalValPercentage);
        },
        complete: function(xhr) {
            status.html(xhr.responseText);
            alert('Good Luck Your File or Images Uploaded Successfully');
            window.location.href = "/live-img-file-upload-example";
        }
    });

    })();
</script>
</body>
</html>

Step 4 :

and last step to finally I am 100% successfully ready to Laravel project run DataTables Server-side Processing in Laravel Therefor run bellow simple command ro quick On terminal run

  SQL create table primary key Autoincrement

Note :We must have to make a simple dirctory Name “files” folder with 777 full rights permissions.

php artisan serve

Step 5 : Run url on your browser

and then We can open this bellow url on your any mozila, chrome or any browser:

http://localhost:8000/live-img-file-upload-example

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel File Upload Progress Bar Example Tutorial From Scratch.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

  Error incorrect format parameter phpmyadmin

Leave a Reply

avatar
  Subscribe  
Notify of