有没有替代file_get_contents?

 key920721 发布于 2023-02-08 17:51

有没有替代file_get_contents?这是我遇到问题的代码:

if ( !$img = file_get_contents($imgurl) ) { $error[] = "Couldn't find the file named $card.$format at $defaultauto"; }
else {
    if ( !file_put_contents($filename,$img) ) { $error[] = "Failed to upload $filename"; }  
    else { $success[] = "All missing cards have been uploaded"; }
}

我尝试使用cURL,但无法弄清楚如何完成这项工作.任何帮助表示赞赏!

1 个回答
  • file_get_contents有很多替代方案我在下面发布了几个替代方案.

    FOPEN

    function fOpenRequest($url) {
       $file = fopen($url, 'r');
       $data = stream_get_contents($file);
       fclose($file);
       return $data;
    }
    $fopen = fOpenRequest('https://www.example.com');// This returns the data using fopen.
    

    卷曲

    function curlRequest($url) {
       $c = curl_init();
       curl_setopt($c, CURLOPT_URL, $url);
       curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
       $data = curl_exec($c);
       curl_close($c);
       return $data;
    }
    $curl = curlRequest('https://www.example.com');// This returns the data using curl.
    

    您可以使用这些可用选项之一与存储在变量中的数据来预先形成您需要的内容.

    2023-02-08 17:54 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有