如何从 PHP 中的 URL 上传图像
在 PHP 中使用 GD 或 imagemagick 如何从 URL 上传照片,我想构建一个可以传递一些参数并上传图像的函数,我现在可以上传一张大图像,将其调整为较小的大小,然后调整一些大小更多缩略图并将 1 个图像中的所有缩略图保存到该位置,但我想添加从 URL 获取图像的功能,然后在其上运行我的代码以调整大小并制作缩略图。
我会使用curl还是其他任何例子或想法将不胜感激
In PHP using GD or imagemagick how can I uplaod a photo from a URL, I want to build a function that I can pass in a few parameters and uplaod the image, I can currentyl uplaod a big image, resize it smaller, then resize some more thumbnails off it and save all into there locations from 1 image but I would like to add the ability to get an image from a URL and then run my code on it to resize and make thumbs.
Would I use curl or something else any example or ideas would be greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这两个函数上的
@
是为了防止 PHP 在 URL 不是有效图像时抛出错误。The
@
on both functions are there to prevent PHP from throwing errors if the URL is not a valid image.根据您的 PHP 配置,fopen 可能会也可能不会直接允许:
http://php.net/manual/en/function.fopen.php
或者,您可以打开一个套接字 (http://php.net/manual/en /book.sockets.php) 并写入/读取 HTTP (http://www .faqs.org/rfcs/rfc2616.html)直接。我不会使用curl,除非你非常小心权限(尤其是执行),或者可以保证没有恶意者可以访问该工具,因为你将有效地打开潜在的攻击途径(好吧,严格来说,你已经是,但这有几种不同的滥用方式)
Depending on your PHP configuration, fopen may or may not allow for it directly:
http://php.net/manual/en/function.fopen.php
Alternatively, you can open a socket (http://php.net/manual/en/book.sockets.php) and write / read HTTP (http://www.faqs.org/rfcs/rfc2616.html) directly. I wouldn't use curl unless you're VERY careful about permissions (especially execute), or can guarantee noone malicious will have access to the tool, as you'll effectively open a potential avenue of attack (well, strictly speaking, you already are, but this has a few different ways it can be abused)
// 假设 url fopen 包装器已启用
// assuming url fopen wrappers are enabled