Laravel - 从字符串路径获取文件的实例 [英] Laravel - Get instance of file from string path

查看:246
本文介绍了Laravel - 从字符串路径获取文件的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的laravel应用程序成功地将我的文件上传并存储在我想要的位置。但是,我不想将文件的公共URL存储在数据库中,而是将它们存储在我的 public 目录中)和显示上传链接列表。



如何从 File :: files(public_path() / files / uploads); 这样我就可以得到名字,大小,修改日期等等。



帮助!

解决方案

  foreach(File :: allFiles($ directory)as $ file) 
{
/ * $ file应该是一个Symfony \Component\Finder\SplFileInfo对象* /
$ file-> getSize();
$ file-> getFilename();
$ file-> getType();

SplFileInfo的文档。 (谢谢@Bogdan!)


My laravel application successfully uploads and stores my files where I want them to. However, I don't want to store the public url of the file in the database, and instead get them on the fly (they're stored in my public directory) and show a list of links to the uploads.

How can I retrieve File objects from just the strings returned by File::files(public_path() . "/files/uploads"); so I can get the name, size, modified date, etc?

Thanks in advance for any help!

解决方案

foreach (File::allFiles($directory) as $file)
{
    /* $file should be a Symfony\Component\Finder\SplFileInfo object */
    $file->getSize();
    $file->getFilename();
    $file->getType();
}

Documentation for the SplFileInfo. (Thanks @Bogdan!)

这篇关于Laravel - 从字符串路径获取文件的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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