在laravel中上传文件 [英] Upload file in laravel
问题描述
伙计们,我阅读了有关在laravel中上传文件的文档...但是我不太了解(我是初学者)这是我的image.blade.php
I guys I read the documentation for do a upload file in laravel... But I don't understand more it (I'm beginner) It's my image.blade.php
{{Form::open(['url'=>'administrator/store ', 'files' => true])}}
{!!Form::file('image') !! }
{!! Form::submit('next')!!}
{{Form::close()}}
管理员控制器
use Storage;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
public function store(Request $request) {
Storage::put($request->image, 'test') ;
}
我不明白我将在函数中添加什么...请帮助我...问候!
I don't understand what I will put into the function..... Help me pls... Greetings!
推荐答案
\ Illuminate \ Http \ Request :: file()
是您上传文件时拥有的.
\Illuminate\Http\Request::file()
is what you have when you're uploading files.
这只是 \ Symfony \ Component \的实例HttpFoundation \ File \ UploadedFile 类,因此您可以将文件移动到目标位置/存储您想要的内容,
This is just a instance of \Symfony\Component\HttpFoundation\File\UploadedFile class so you can move file to destination/storage what you want, something like that:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MainController extends Controller
{
public function upload(Request $request)
{
/**
* @var \Symfony\Component\HttpFoundation\File\UploadedFile
*/
$uploadedFile = $request->file('image');
if ($uploadedFile->isValid()) {
$uploadedFile->move(destinationPath, $fileName);
}
}
}
因此,您以错误的方式使用了 \ Illuminate \ Filesystem \ Filesystem :: put()
.下面是该方法的实现方式:
Aso, you've been used \Illuminate\Filesystem\Filesystem::put()
in a wrong way. Below is like that method is implemented:
/**
* Write the contents of a file.
*
* @param string $path
* @param string $contents
* @param bool $lock
* @return int
*/
public function put($path, $contents, $lock = false)
{
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
}
这篇关于在laravel中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!