fenos's avatar

Upload Images with FileSystem L5

Hi guys, I'm trying to manage the upload of picture with flilesystem.

As Example to see how it works I made a single form that post to this method:

public function upload(Request $request, Filesystem $filesystem) {

       $image = $request->file('image');
       $filesystem->put('local/test.jpg',$image);
}

The file is successfully created but it's not possible open it. I tried using the move method as well, but the image won't be detected in the tmp file.

If you guys have experience with it, may you point me on how to store images after they've been uploaded? Thanks

0 likes
4 replies
DNABeast's avatar

I don't have a heap of experience here but is that a typo? $flilesystem? It looks like your method isn't injected properly.

lara8818's avatar
Level 1

If the image is appearing corrupted it's because you're storing it as the image's tmp name (I believe). Try changing it to

$filesystem->put('local/test.jpg', file_get_contents($image));

If you're talking about how to access the URL to where the image is being stored, then I am sadly in the same boat as you!

1 like
DNABeast's avatar

It may be that you need to use the copy method.

$tempfilename = $request->file('image')->getRealPath();
$filesystem->copy($tempfilename, 'local/test.jpg');

Please or to participate in this conversation.