使用Laravel上传和存储文件 [英] Uploading and storing file with Laravel

查看:46
本文介绍了使用Laravel上传和存储文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel illuminate/html ,并且尝试上载图像文件并将其存储在laravel安装文件夹的/public 中.我已经从请求中获得了图片:

I am using Laravel illuminate/html and I am trying to upload an image file and store it in /public in the laravel installation folder. I have got the image from the request:

$img = Request::file('img');

如何将其存储在公用文件夹中?

How can I store it in the public folder?

谢谢

推荐答案

您可以在控制器中执行此操作:

You could do this in your controller:

Request :: file('img')-> move(base_path('public/uploads'));

或者如果您想指定通用文件名或更改文件名

Or if you wish to specify a generic filename or change filename

$newfilename = str_random(32) .time();

 $ newfilename = $newfilename. ".". Request::file('img')->guessClientExtension();



 Request::file('img')->move(base_path('public/uploads'), $newfilename);`

这篇关于使用Laravel上传和存储文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆