I am trying to make a website where the user will be able to upload the pdf and doc file. Also, I want to save the file in the storage folder so I made the symlink so it would replicate the folder in the Public folder. SO I have a folder called Public/storage/Paper in public. This is my form where the user will be able to upload the paper.
I am trying to make a website where the user will be able to upload the pdf and doc file. Also, I want to save the file in the storage folder so I made the symlink so it would replicate the folder in the Public folder. SO I have a folder called Public/storage/Paper in public. This is my form where the user will be able to upload the paper.
<form class="form-horizontal" method="post" action="paper" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="title">Title of Paper</label>
<input type="text" class="form-control" name="title" placeholder="Title of Paper" required="required">
</div>
<div class="form-group">
<label for="Paper">Upload Paper</label>
<input type="file" class="form-control" name="paper" required="required" >
</div>
<button type="submit" class="btn btn-primary">Submit</button>
On my controller, I wrote this code, this works perfectly fine like saving the data in the database when I don't need to upload the file. But when I need to upload the paper the validation doesn't pass.
<?php
namespace App\Http\Controllers;
use App\Submission;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
class PapersController extends Controller
{
public function store(Request $request){
$request->validate([
'title'=>'required',
'paper'=>'required'
]);
$title= $request->input('title');
Validator::make($request->all(),['paper'=>"required|string|mimes:pdf,zip"])->validate();
$extension= $request->file("file")->getClientOriginalExtension();
$stringPaperFormat=str_replace(" ", "", $request->input('title'));
$fileName= $stringPaperFormat.".".$extension;
$FileEnconded= File::get($request->paper);
Storage::disk('local')->put('public/Paper'.$fileName, $FileEnconded);
$newsubmission= array("title"=>$title, "paper"=>$fileName);
$created= DB::table('submissions')->insert($newsubmission);
if($created){
return "Sucessful";
}else{
return "Not Sucessful";
}
}
}
I am not being able to detect the problem. Any kind of help will be appreciated.