Se sube un archivo y se devuleve la primera pagina
This commit is contained in:
parent
e0c33f23e2
commit
7161404b4c
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class FileUploadController extends Controller {
|
||||||
|
|
||||||
|
|
||||||
|
public function fileUploadPost(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'file' => 'required|mimes:pdf|max:2048',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fileName = time().'.'.$request->file->extension();
|
||||||
|
$request->file->move(public_path('uploads'), $fileName);
|
||||||
|
|
||||||
|
return redirect()->route("process", ['fileName' => $fileName]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,9 +8,8 @@ use Illuminate\Http\Request;
|
||||||
class LibrilladoraController extends Controller
|
class LibrilladoraController extends Controller
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
public function process(Request $request) {
|
public function process($fileName) {
|
||||||
$nombre = $request->input("Archivo");
|
|
||||||
$lib = new Librilladora();
|
$lib = new Librilladora();
|
||||||
$lib->prueba($nombre);
|
$lib->prueba($fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,28 @@ namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
|
||||||
class Librilladora extends Model {
|
class Librilladora extends Model {
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
public function prueba(string $nombre) {
|
public function prueba(string $fileName) {
|
||||||
$mpdf = new \Mpdf\Mpdf();
|
$mpdf = new \Mpdf\Mpdf();
|
||||||
|
|
||||||
// Write some HTML code:
|
// // Write some HTML code:
|
||||||
$mpdf->WriteHTML($nombre);
|
// $mpdf->WriteHTML($nombre);
|
||||||
|
//
|
||||||
|
// // Output a PDF file directly to the browser
|
||||||
|
// $mpdf->Output();
|
||||||
|
//
|
||||||
|
// // Require composer autoload
|
||||||
|
// require_once __DIR__ . '/vendor/autoload.php';
|
||||||
|
$file = 'uploads/'.$fileName;
|
||||||
|
$pagecount = $mpdf->SetSourceFile($file);
|
||||||
|
$tplId = $mpdf->importPage(1);
|
||||||
|
$mpdf->useTemplate($tplId);
|
||||||
|
File::delete($file);
|
||||||
|
|
||||||
// Output a PDF file directly to the browser
|
|
||||||
$mpdf->Output();
|
$mpdf->Output();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,9 @@
|
||||||
|
|
||||||
<div class="mt-8 bg-white dark:bg-gray-800 overflow-hidden shadow sm:rounded-lg">
|
<div class="mt-8 bg-white dark:bg-gray-800 overflow-hidden shadow sm:rounded-lg">
|
||||||
<div class="p-6">
|
<div class="p-6">
|
||||||
<form id="archivo" method="post" action="{{route('process')}}">
|
<form id="archivo" action="{{ route('file.upload.post') }}" method="POST" enctype="multipart/form-data">
|
||||||
@csrf
|
@csrf
|
||||||
<input required name="Archivo" type="text" class="formulario">
|
<input required name="file" type="file" class="formulario">
|
||||||
<input type="submit" value="Cargar archivo">
|
<input type="submit" value="Cargar archivo">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\LibrilladoraController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\EventoController;
|
use App\Http\Controllers\FileUploadController;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
@ -18,5 +19,6 @@ Route::get('/', function () {
|
||||||
return view('welcome');
|
return view('welcome');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::post('/processed', [\App\Http\Controllers\LibrilladoraController::class, 'process'])->name('process');
|
Route::get('/processed/{fileName}', [LibrilladoraController::class, 'process'])->name('process');
|
||||||
|
|
||||||
|
Route::post('file-upload', [FileUploadController::class, 'fileUploadPost'])->name('file.upload.post');
|
||||||
|
|
Loading…
Reference in New Issue