如何在 Laravel 5.0 中获取上传文件的 tmp_name
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28457734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get uploaded file's tmp_name in Laravel 5.0
提问by Mathieu Dumoulin
Using Laravel 5, i've been trying to take an uploaded file and move it using the filesystem facade to profit from the flysystem's power used by Laravel.
使用 Laravel 5,我一直在尝试获取上传的文件并使用文件系统外观移动它,以从 Laravel 使用的 flysystem 功能中获利。
The problem is, even if i try to get the path, tmp_name, diskname or wathever property that would represent the $_FILES[file][tmp_name] i can't seem to get access to it!
问题是,即使我尝试获取表示 $_FILES[file][tmp_name] 的路径、tmp_name、diskname 或 wathever 属性,我似乎也无法访问它!
I don't want to use $_FILES as it contravenes best practices and if something were to change it wouldn't work anymore so i really want to use:
我不想使用 $_FILES ,因为它违反了最佳实践,如果要更改某些内容,它将不再起作用,所以我真的想使用:
$request->file('import')
to get access to my imported file.
访问我导入的文件。
There is a move method in the UploadedFile class but i need to set a local path which is not necessarely the case. Then there is a move meethod in the FileSystem contract but it asks for a local path that i'm not aware of cause i can't find the local tmp_name of the UploadedFile...
UploadedFile 类中有一个 move 方法,但我需要设置一个本地路径,但不一定是这样。然后在 FileSystem 合同中有一个移动方法,但它要求一个我不知道的本地路径,因为我找不到 UploadedFile 的本地 tmp_name ...
How would i go doing this, i'm really lost here.
我该怎么做,我真的迷路了。
回答by Mathieu Dumoulin
Why is it that i find my answer always after posting the question...
为什么我总是在发布问题后找到我的答案...
The answer to this question is simple, use the SplFileInfo features:
这个问题的答案很简单,使用 SplFileInfo 特性:
The object returned by the file method is an instance of the Symfony\Component\HttpFoundation\File\UploadedFile class, which extends the PHP SplFileInfo class and provides a variety of methods for interacting with the file.
file方法返回的对象是Symfony\Component\HttpFoundation\File\UploadedFile类的一个实例,它扩展了PHP SplFileInfo类,提供了多种与文件交互的方法。
So you can do
所以你可以做
$request->file('import')->getPathName()
And it will return your local path!
它将返回您的本地路径!