【问题标题】:how to download users twitter images from API with php如何使用 php 从 API 下载用户 Twitter 图像
【发布时间】:2020-10-07 20:54:53
【问题描述】:

我正在尝试下载在我的网站上注册的 twitter 用户图像,以便我可以将它们保存在我的文件中,以便稍后插入我的数据库以在我的网站中使用。

这是我的推特 API:

 $user_pic = $user_info->profile_image_url_https;

我试过了,它可以工作,但我希望它将图像下载到我的基本文件 profilePictures/:

$twitterimage = file_get_contents($user_pic);
    $fp = fopen('path_to_filename.png', 'w');
    fwrite($fp, $twitterimage); 
    fclose($fp); 

现在正在下载,但我如何下载 twitter 图片并将它们保存在我的基本文件“profilePictures/”中?

【问题讨论】:

    标签: php html twitter-bootstrap twitter-oauth


    【解决方案1】:

    我找到了解决办法,我要做的就是这个

    $user_pic= str_replace('_normal','',$user_pic);
        $Imgurl = $user_pic;
        $target_path = "profilePictures/";
        $filename = basename($Imgurl);
        $saveLoc = $target_path . $filename;
        file_put_contents($saveLoc, file_get_contents($Imgurl));
    

    然后将$saveLoc 变量保存到我的数据库中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-01
      • 2013-01-28
      • 2017-10-13
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 2014-02-24
      相关资源
      最近更新 更多