Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get uploaded file's tmp_name in Laravel 5.0

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.

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!

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.

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.

like image 538
Mathieu Dumoulin Avatar asked Dec 09 '22 04:12

Mathieu Dumoulin


1 Answers

Why is it that i find my answer always after posting the question...

The answer to this question is simple, use the SplFileInfo features:

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.

So you can do

$request->file('import')->getPathName()

And it will return your local path!

like image 80
Mathieu Dumoulin Avatar answered Dec 10 '22 23:12

Mathieu Dumoulin