Download Remote File to Server with PHP

前端 未结 8 635
刺人心
刺人心 2020-12-09 12:10

I\'ve been looking all over the place for the last two days and trying everything and still can\'t get anything to work. I feel like this should be a relatively simple thin

相关标签:
8条回答
  • 2020-12-09 12:36
    $url  = 'http://www.example.com/a-large-file.zip';
    $path = '/path/to/a-large-file.zip';
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $data = curl_exec($ch);
    
    curl_close($ch);
    
    file_put_contents($path, $data);
    

    it uses curl

    $url is the file url

    $path is where and the name to save the file

    i hope it works

    0 讨论(0)
  • 2020-12-09 12:38

    file_put_contents expects a filename, not a directory name.

    0 讨论(0)
提交回复
热议问题