dongyou5098 2013-08-07 18:59
浏览 16

如何将图像从链接上传到我的服务器?

I have facebook login and signup on my site. I have looked here and there and i am trying to upload image from link.

suppose this is link of image as i wanted to upload image from facebook

http://graph.facebook.com/shaverm/picture?type=large

this will change into

http://m.ak.fbcdn.net/profile.ak/hprofile-ak-ash4/372183_100002526091955_998385602_n.jpg

Now i want it to upload on my site

this image:

http://m.ak.fbcdn.net/profile.ak/hprofile-ak-ash4/372183_100002526091955_998385602_n.jpg

I have found this code here on stackoverflow but i am not sure how this will work out i am trying this from last 2 hours and trying to figure it out but not able to do so i posted here.

$image = @ImageCreateFromString(@file_get_contents($imageURL));

if (is_resource($image) === true){
    // image is valid, do your magic here
}else{
    // not a valid image, show error
}

This are my code from which i upload picture right now on my site.

if ($_FILES) {
    $name = $_FILES['filename']['name'];
    $size = $_FILES["filename"]["size"];
    switch ($_FILES['filename']['type']) {
        case 'image/jpeg':
            $ext = 'jpg';
            break;           
        default:
            $ext = '';
            break;
}
if ($ext) {
    if ($size > 800000) {
        $imagefalse = '<span id="font">Image is bigger in size sorry!<br / ></span>';
    } else {
        $path = $imagelink; // old path of image
        unlink($path); // remove old file if any
        $timestamp = time();
        $n = "image/user/$id.$timestamp.$ext";
        move_uploaded_file($_FILES['filename']['tmp_name'], $n);
        $setnewimage = mysql_query("UPDATE users SET image='$n' WHERE id='$id'");
    }
} else
    $imagefalse = '<span id="font">File is not an accepted image file<br / ></span>';
}
  • 写回答

1条回答 默认 最新

  • dongzhui4927 2013-08-07 19:02
    关注

    You probably need curl; it is a HTTP (& FTP) client library.

    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本