首页 > 解决方案 > 使用 PHP 从 HTTP 下载文件

问题描述

我正在尝试使用 PHP 从此链接http://192.168.1.9:8080/savegame4下载文件,但它给了我一个错误提示

file_get_contents( http://192.168.1.9:8080/savegame4 ):打开流失败:HTTP 请求失败!HTTP/1.1 404

该链接是下载的直接链接,因为我无法获得其他链接

这是我下面的代码。

$url = 'http://192.168.1.9:8080/savegame4'; 
  
$file_name = basename($url); 

if(file_put_contents( $file_name,file_get_contents($url))) { 
    echo "File downloaded successfully"; 
} 
else { 
    echo "File downloading failed."; 
}

标签: phpdownload

解决方案


推荐阅读