J'essaie de télécharger une vidéo en utilisant Laravel. Bien que le téléchargement des images fonctionne correctement pour moi lorsque je change de ligne de contrôleur
echo '$file' . $file->getClientOriginalName() . '"/>';
à:
echo '<file src="uploads/' . $file->getClientOriginalName() . '"/>';
Je ne vois que uploaded
écrit sur une nouvelle page, mais pas de vidéo.
Manette:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Request;
class UploadController extends Controller
{
public function upload(Request $request)
{
if(Request::hasFile('file')){
echo 'Uploaded';
$file = Request::file('file');
$file->move('uploads', $file->getClientOriginalName());
echo '$file' . $file->getClientOriginalName() . '"/>';
}
}
}
Itinéraires:
Route::get('/', function () {
return view('welcome');
});
Route::post('upload', 'UploadController@upload');
Vue:
<html>
<head>
<title>Laravel</title>
<link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="container">
<div class="content">
<h1>File Upload</h1>
<form action="{{ URL::to('upload') }}" method="post" enctype="multipart/form-data">
<label>Select image to upload:</label>
<input type="file" name="file" id="file">
<input type="submit" value="Upload" name="submit">
<input type="hidden" value="{{ csrf_token() }}" name="_token">
</form>
</div>
</div>
</body>
</html>
Vous pouvez essayer comme ça:
Manette :
use Illuminate\Support\Facades\Request;
class UploadController extends Controller
{
public function upload(Request $request)
{
if(Request::hasFile('file')){
$file = Request::file('file');
$filename = $file->getClientOriginalName();
$path = public_path().'/uploads/';
return $file->move($path, $filename);
}
}
}
les fichiers php.ini contiennent des limites pouvant l’affecter. Essayez de les remplacer par des valeurs suffisamment élevées:
upload_max_filesize = 10M
post_max_size = 10M
memory_limit = 32M
public function upload_video(Request $request){
$data=$request->all();
$rules=[
'video' =>'mimes:mpeg,ogg,mp4,webm,3gp,mov,flv,avi,wmv,ts|max:100040|required'];
$validator = Validator($data,$rules);
if ($validator->fails()){
return redirect()
->back()
->withErrors($validator)
->withInput();
}else{
$video=$data['video'];
$input = time().$video->getClientOriginalExtension();
$destinationPath = 'uploads/videos';
$video->move($destinationPath, $input);
$user['video'] =$input;
$user['created_at'] =date('Y-m-d h:i:s');
$user['updated_at'] =date('Y-m-d h:i:s');
$user['user_id'] =session('user_id');
DB::table('user_videos')->insert($user);
return redirect()->back()->with('upload_success','upload_success');
}
}