简体   繁体   English

PHP/Laravel - 将图像(PNG)从 base64 保存到 FTP 服务器而不在本地保存

[英]PHP/Laravel - Saving an image(PNG) from a base64 to an FTP Server without saving it locally

I'm using laravel to get a post request base64.我正在使用 laravel 来获取发布请求 base64。 then on the controller, I want to decode the base64 to a png file and then immediately store the file to the FTP storage without saving it to my local(Public Folder) folder.然后在 controller 上,我想将 base64 解码为 png 文件,然后立即将文件存储到 FTP 存储而不保存到我的本地文件夹。 This is my Controller这是我的Controller

 $path     = "test/image.png";
 $image    = explode(',',$imgbg);
 $base64   = $image[1];
 $result   = base64_decode($base64);

 file_put_contents("ori.png", $result);

 Storage::disk('ftp-dev')->put($path, file_get_contents("ori.png"));

as of now, it save the file locally and then get the file contents to save it to an FTP server.截至目前,它将文件保存在本地,然后获取文件内容以将其保存到 FTP 服务器。 Is there a way to do it so it doesn't save the file locally and just save it in the FTP server?有没有办法做到这一点,它不会在本地保存文件,而只是将它保存在 FTP 服务器中? any suggestions are welcome and appreciated.欢迎和赞赏任何建议。

My solution is:我的解决方案是:

Storage::disk('ftp-dev')->put($path, $result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM