将图片从另一个域名url上传到我的服务器
upload image from another domain url to my server
我正在运行angularjs和laravel,并计划将facebook上的用户配置文件上传到我的服务器上,并将其加载到画布上。
因为画布在加载其他域时存在CORS问题,同时将其更改为dataUrl。
那么,在fb域上获取图像的url并上传到我的服务器
首先必须从API获取配置文件图片的URL。为此,您必须向http://graph.facebook.com/v2.5/me?fields=picture
请求,并提供您的访问令牌。
它将返回类似以下内容:
{
"picture": {
"data": {
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpt1/v/t1.0-1/p50x50/picture.jpg"
}
},
"id": "10000userid"
}
所以你必须只得到有趣的部分:
// requesting
$get = file_get_contents('http://graph.facebook.com/v2.5/me?fields=picture&access_token=YOUR_ACCESS_TOKEN_HERE');
// parsing
$get = json_decode($get);
// getting the part you want
$picture_url = $get->picture->data->url;
从Facebook API获取图像URL后,您只需:
// download it
$download = file_get_contents($picture_url);
// get extension (I'm not sure if Facebook really converts everything to JPEG, I'm not a huge Facebook user)
$extension = strtolower(end(explode(".", $download)));
// save it on your server
file_put_contents('path/to/save.'.$extension, $download);
$url = 'https://yourimageurl.com/test.png';
$img = 'foo.png';
file_put_contents($img, file_get_contents($url));
相关文章:
- 将Adobe创意编辑的图像上传到我的服务器,而不是他们的创意云
- 有没有一种方法可以生成Braintree令牌,而不必向我的服务器添加PHP脚本
- 为什么我的服务器从不接收WebSocket发送
- 为什么可以't我得到连接客户端's的ip地址在我的服务器上运行Node.js+Openshift托管的W
- 如何在我的服务器上创建javascript,该服务器使用该服务器上的后端,并将在另一个网站上使用
- 如何获取我的网站(我的服务器)用户的MAC地址
- Ajax脚本让我的服务器忙得不可开交.让其他人来做这件事
- 我的页面总是将我重定向到我的服务器
- 没有“访问控制允许来源”错误,即使标头在我的服务器端代码上
- 不知道为什么我的服务器超时.
- 用户如何从我的服务器获取数据作为通往Facebook的桥梁
- JavaScript 在我的服务器上不起作用
- 将 mp3 文件从另一台服务器下载到我的服务器
- 安全性 - 将数据从第三方发送到我的服务器 Ajax php
- 将变量存储到我的服务器
- 配置实习生以设置/拆除我的服务器模拟
- 谷歌地图自定义制作工具没有出现在我的服务器上,但适用于本地主机
- 使用javascript从我的服务器上的文件进行实时更新
- Jquery show/hide 在我的服务器上不起作用
- 我的服务器正在寻找一个文件,但我有一个字符串,我将如何通过jquery模拟文件上传