Form::file('file_name');
Form::open(array('url' => '/uploadfile','files'=>'true'));
resources/views/uploadfile.php
<html> <body> <?php echo Form::open(array('url' => '/uploadfile','files'=>'true')); echo '選擇一個要上傳的檔案:<br/>'; echo Form::file('image'); echo Form::submit('提交上傳'); echo Form::close(); ?> </body> </html>
D:\laravel>php artisan make:controller UploadFileController
app/Http/Controllers/UploadFileController.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()); } }
app/Http/routes.php
Route::get('/uploadfile','UploadFileController@index'); Route::post('/uploadfile','UploadFileController@showUploadFile');
http://localhost:8000/uploadfile