如何在Laravel 5.0中获取上传文件的tmp_name [英] How to get uploaded file's tmp_name in Laravel 5.0
问题描述
使用Laravel 5,我一直在尝试获取上传的文件,并使用文件系统外观将其移动,以从Laravel使用的flysystem的功能中获利.
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.
问题是,即使我尝试获取表示$ _FILES [file] [tmp_name]的路径,tmp_name,diskname或wathever属性,我似乎也无法访问它!
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,因为它违反了最佳实践,如果要进行更改,它将不再起作用,所以我真的想使用:
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:
$request->file('import')
获得对我导入文件的访问权限.
to get access to my imported file.
UploadedFile类中有一个move方法,但是我需要设置一个不一定是这种情况的本地路径.然后在FileSystem合同中有一个移动方法,但是它要求我不知道的本地路径,原因是我找不到UploadedFile的本地tmp_name ...
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...
我将如何去做,我真的在这里迷路了.
How would i go doing this, i'm really lost here.
推荐答案
为什么我总是在发布问题后总是找到答案...
Why is it that i find my answer always after posting the question...
这个问题的答案很简单,请使用SplFileInfo功能:
The answer to this question is simple, use the SplFileInfo features:
file方法返回的对象是的实例. Symfony \ Component \ HttpFoundation \ File \ UploadedFile类,其中 扩展了PHP 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.
所以你可以做
$request->file('import')->getPathName()
它将返回您的本地路径!
And it will return your local path!
这篇关于如何在Laravel 5.0中获取上传文件的tmp_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!