Download Remote File to Server with PHP

前端 未结 8 651
刺人心
刺人心 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条回答
  •  萌比男神i
    2020-12-09 12:20

    Use curl to download file from remote server like below.

    $url = "http://path/toserver/filename";
    $destination = "uploads/filename";    
    $fp = fopen ($destination, 'w+');
      $ch = curl_init();
      curl_setopt( $ch, CURLOPT_URL, $url );
      curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
      curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    
      curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
      curl_setopt( $ch, CURLOPT_FILE, $fp );
      curl_exec( $ch );
      curl_close( $ch );
      fclose( $fp );
    

    reference http://www.tricksofit.com/2014/04/download-file-from-remote-server-in-php

提交回复
热议问题