How to download file from url that redirects in Laravel?(如何从在 Laravel 中重定向的 url 下载文件?)
问题描述
我在从 summernote 下载内嵌图像时遇到问题从 GMAIL 复制图像时.
Gmail 返回这样的链接:
https://mail.google.com/mail/u/0?ui=2&ik=d3d2b70b46&attid=0.2&permmsgid=msg-f:1651797278805284123&th=16ec5cdf9c&view=fimg;sz=s0-l75-ft&attbid=ANGjdJ9_MfHq-YioubDagNZ5h216toG9gPg11wV4SkG0Q73urVHcSFnjGKdM4b6b7BfEir0xUp3f4A2ULo9A2srvL7svlpHpZ3RampLdPhlpHpHpZ3RampLvLvlpHpLz&L&L&L像这样重定向到动态 URL:
<预> <代码> https://gm1.ggpht.com/puicw0cCLZ4huu-Pwk3VHJ8R-wdB2bIHYi4v4F8yUxSnt0UpQQ5LArR9szM5JIqNHPo7JBUbFIf0nsh4JKakewl91Zl08pnNcxmMah6tAFNFWOFaiVJDhxA4RGHvyFxP90HR2DLKHL1MAz8TC9zY8qEliO3vxCv-KqNfq0WBvkFY2fb2GvAWtSTNhksmSHV8_pAKVRyT5aGnbmlH1SWRk_HmTfH27aoslF1P_Lc0245h2nwuhBQ6WpoMgE8eij_Z0QWrHqJWHB0xhAIFAdtIb5E
我使用这个file_get_contents($link)
失败了,因为我无法获得图片的原始链接
如何在 Laravel 控制器中获取图片的原始链接?
注意:这些只是虚拟网址.
我的问题与此类似:如何从 url 下载文件重定向?但我似乎无法找到它的 Laravel 版本.
我们需要启用重定向.
$opts = array('http' =>大批('follow_location' =>1、));$context = stream_context_create($opts);$result = file_get_contents('http://example.com/', false, $context);
默认情况下,根据 docs 文档,重定向是已启用,但我出于教育目的在上面明确启用了它.
I'm having a problem with downloading an inline image from summernote when the image is copied from GMAIL.
The Gmail returns link like this:
https://mail.google.com/mail/u/0?ui=2&ik=d3d2b70b46&attid=0.2&permmsgid=msg-f:1651797278805284123&th=16ec5cdf9c25551b&view=fimg&sz=s0-l75-ft&attbid=ANGjdJ9_MfHq-YioubDagNZ5h216toG9gPg11wV4SkG0Q73urVHcSFnjGKdM4b6b7BfEir0xUp3f4A2ULo9A2srvLz4hlMdP727bJYHpSyL92kesSl3W74lRZFs9HBU&disp=emb&rv71
Which redirects to dynamic URL like this:
https://gm1.ggpht.com/puicw0cCLZ4huu-Pwk3VHJ8R-wdB2bIHYi4v4F8yUxSnt0UpQQ5LArR9szM5JIqNHPo7JBUbFIf0nsh4JKakewl91Zl08pnNcxmMah6tAFNFWOFaiVJDhxA4RGHvyFxP90HR2DLKHL1MAz8TC9zY8qEliO3vxCv-KqNfq0WBvkFY2fb2GvAWtSTNhksmSHV8_pAKVRyT5aGnbmlH1SWRk_HmTfH27aoslF1P_Lc0245h2nwuhBQ6WpoMgE8eij_Z0QWrHqJWHB0xhAIFAdtIb5E
I failed using this file_get_contents($link)
because I can't get the original link of the image
How can I get the original link of the image in the Laravel Controller?
Note: These are just dummy URLs.
My question is similar to this: How to download file from url that redirects? But I can't seem to find a Laravel version of that.
We need to enable redirection.
$opts = array('http' =>
array(
'follow_location' => 1,
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/', false, $context);
By default, according to the docs docs, redirection is enabled, however I explicitly enabled it above for educational purposes.
这篇关于如何从在 Laravel 中重定向的 url 下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从在 Laravel 中重定向的 url 下载文件?
基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01