douyimin1083 2017-05-18 16:10
浏览 297
已采纳

Laravel 5存储来自URL的图像

I'm trying to store an image from a URL using Intervention to my storage.

Here is what I tried so far(Attempt 1):

$path = 'http://f2b9x.s87.it/images/1/FR_laura-kithorizontal.gif';
$filename = basename($path);
$image = Image::make($path);
$store = $image->storeAs('image/'.$filename,'public');

But I get this error: Command (storeAs) is not available for driver (Gd).

Then I tried this (Attempt 2):

Image::make('http://f2b9x.s87.it/images/1/FR_laura-kithorizontal.gif')->save(public_path('/images/saveAsImageName.jpg'));

But I got this error: Can't write image data to path (C:\xampp\htdocs\app\public\/images/saveAsImageName.jpg)

In Attempt 2, I tried doing also this: public_path('\images\saveAsImageName.jpg') just to make sure it wasn't the backslashes causing the problem, but it gave me the same error.

Any help?

  • 写回答

2条回答 默认 最新

  • duanmianxue2687 2017-05-19 14:21
    关注

    The problem was that I didn't have the directories created (thanks @Tim Lewis)

    I solved it like this:

    use File;

    File::makeDirectory(public_path('images/kits/'.$microtime), 0775, true);

    The first parameter is the path
    The second parameter is the privileges given to that folder
    The third parameter is normally by default false, but if true, it creates the directories recursively. Meaning that it first checks if images is created, then kits, and then (in this case) if the folder with that microtime is created.
    If none exist, it creates all of them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于52单片机的酒精浓度检测系统加继电器和sim800
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等