다운로드 URL 에서 파일 서버

뭐, 이 한 것인데, 아주 간단한 것 같다. 네가 해야 할 일은 서버에 파일을 다운로드할 수 있다.

file_put_contents("Tmpfile.zip", file_get_contents("http://someurl/file.zip"));

만 한 문제가 있습니다. 많은 경우, 어떤 파일 같은 100mb. 그런 다음, 메모리 부족 및 파일을 다운로드하십시오 실행할 수 없습니다.

나는 내가 원하는 파일을 다운로드하여 backup-to-disk 기록하십시오 수 있는 방법입니다. 더 큰 문제 없이 실행 파일을 메모리로 다운로드하십시오 이쪽요 수 있어요.

질문에 대한 의견 (1)
해결책

이후 PHP 5.1.0 ['file_put_contents ()'] (http://php.net/file_put_contents) 는 데이터 '는' $ 로 전달하여 먹어서나 조각별로 조각 처리하십니까 스트리밍합니다 매개변수입니다:

file_put_contents("Tmpfile.zip", fopen("http://someurl/file.zip", 'r'));

&Solarisdvd 수작업식:

&gt. 데이터 경우 (즉 두 번째 인수] 는 나머지 버퍼에 지정된 파일을 복사됩니다 스트리밍합니다 리소스에만 iqn 스트리밍합니다. 이러한 상황은 사용 &gt. ['stream_copy_to_stream ()'] (http://php.net/stream_copy_to_stream).

(덕분에 하크레).

해설 (8)
private function downloadFile($url, $path)
{
    $newfname = $path;
    $file = fopen ($url, 'rb');
    if ($file) {
        $newf = fopen ($newfname, 'wb');
        if ($newf) {
            while(!feof($file)) {
                fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
            }
        }
    }
    if ($file) {
        fclose($file);
    }
    if ($newf) {
        fclose($newf);
    }
}
해설 (16)

컬 사용해 보고

set_time_limit(0); // unlimited max execution time
$options = array(
  CURLOPT_FILE    => '/path/to/download/the/file/to.zip',
  CURLOPT_TIMEOUT =>  28800, // set this to 8 hours so we dont timeout on big files
  CURLOPT_URL     => 'http://remoteserver.com/path/to/big/file.zip',
);

$ch = curl_init();
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);

하지만, 'I believe' 옵션을 통해 CURLOPT_FILE i& # 39 m 확신하지 못하고 그대로 가져온 데이터, ie 씁니다. 버퍼된 없습니다.

해설 (5)

위 좁히어 가 작동하지 우치니 이스마일 (등을 통해 프로디지털슨) 코드 (이유: (http://www.webdeveloper.com/forum/showthread.php) 에서 fopen 누각되었습니다 curlopt_file? php 스크립트 파일에 대한 다른 실행하십시오 다운로드하십시오 268299 해결되었으므로 크론조프 오노프스카 php 스크립트). 그래서 나는 내가 너무 적은 수의 방향점 아래에서 설명 추가 칸트 좁히어 베크로스 열거하십시오 apc® 예 (또한 &quot 일하고, 현지 url"):

function downloadUrlToFile($url, $outFileName)
{   
    if(is_file($url)) {
        copy($url, $outFileName); 
    } else {
        $options = array(
          CURLOPT_FILE    => fopen($outFileName, 'w'),
          CURLOPT_TIMEOUT =>  28800, // set this to 8 hours so we dont timeout on big files
          CURLOPT_URL     => $url
        );

        $ch = curl_init();
        curl_setopt_array($ch, $options);
        curl_exec($ch);
        curl_close($ch);
    }
}
해설 (0)
  1. 라는 폴더를 만들어 &quot downloads"; 대상에 서버
  2. [이 코드] '에서' 로 .php 실행하십시오 대상 서버로 저장 파일

다운로더:



<input name="url" size="50" />
<input name="submit" type="submit" />

<?php
    // maximum execution time in seconds
    set_time_limit (24 * 60 * 60);

    if (!isset($_POST['submit'])) die();

    // folder to save downloaded files to. must end with slash
    $destination_folder = 'downloads/';

    $url = $_POST['url'];
    $newfname = $destination_folder . basename($url);

    $file = fopen ($url, "rb");
    if ($file) {
      $newf = fopen ($newfname, "wb");

      if ($newf)
      while(!feof($file)) {
        fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
      }
    }

    if ($file) {
      fclose($file);
    }

    if ($newf) {
      fclose($newf);
    }
?>
해설 (3)
set_time_limit(0); 
$file = file_get_contents('path of your file');
file_put_contents('file.ext', $file);
해설 (4)

3 가지 방법

  1. file_get_contents 및 file_put_contents
  2. fopen

From here 예를 찾을 수 있습니다.

해설 (0)

간단한 방법 () '에서' 복제본에 php 사용

copy($source_url, $local_path_with_file_name);

참고: 만약 덮어씁니다 대상 파일이 이미 존재합니다.

PHP 복제본에 () 함수를

참고: 777 폴더에서는 설정해야 할 대상에 대한 권한. 이 방법을 사용하여 다운로드하십시오 경우 로컬 컴퓨터에.

참고: 권한이 있는 777 는 Unix 기반 시스템, 전체 읽기 / 쓰기 / 실행 할 수 있는 권한을 소유자, 그룹 및 everyone. 일반적으로 우리가 이 권한을 부여할 수 없는 에셋을 여론의 감춰집니다 필요한 대부분의 웹 서버에서. 예: images 폴더.

해설 (3)

내가 이 방법을 사용하여 파일을 다운로드하십시오

function cURLcheckBasicFunctions()
{
  if( !function_exists("curl_init") &&
      !function_exists("curl_setopt") &&
      !function_exists("curl_exec") &&
      !function_exists("curl_close") ) return false;
  else return true;
}

/*
 * Returns string status information.
 * Can be changed to int or bool return types.
 */
function cURLdownload($url, $file)
{
  if( !cURLcheckBasicFunctions() ) return "UNAVAILABLE: cURL Basic Functions";
  $ch = curl_init();
  if($ch)
  {

    $fp = fopen($file, "w");
    if($fp)
    {
      if( !curl_setopt($ch, CURLOPT_URL, $url) )
      {
        fclose($fp); // to match fopen()
        curl_close($ch); // to match curl_init()
        return "FAIL: curl_setopt(CURLOPT_URL)";
      }
      if ((!ini_get('open_basedir') && !ini_get('safe_mode')) || $redirects < 1) {
        curl_setopt($ch, CURLOPT_USERAGENT, '"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //curl_setopt($ch, CURLOPT_REFERER, 'http://domain.com/');
        if( !curl_setopt($ch, CURLOPT_HEADER, $curlopt_header)) return "FAIL: curl_setopt(CURLOPT_HEADER)";
        if( !curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $redirects > 0)) return "FAIL: curl_setopt(CURLOPT_FOLLOWLOCATION)";
        if( !curl_setopt($ch, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)";
        if( !curl_setopt($ch, CURLOPT_MAXREDIRS, $redirects) ) return "FAIL: curl_setopt(CURLOPT_MAXREDIRS)";

        return curl_exec($ch);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, '"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //curl_setopt($ch, CURLOPT_REFERER, 'http://domain.com/');
        if( !curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false)) return "FAIL: curl_setopt(CURLOPT_FOLLOWLOCATION)";
        if( !curl_setopt($ch, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)";
        if( !curl_setopt($ch, CURLOPT_HEADER, true)) return "FAIL: curl_setopt(CURLOPT_HEADER)";
        if( !curl_setopt($ch, CURLOPT_RETURNTRANSFER, true)) return "FAIL: curl_setopt(CURLOPT_RETURNTRANSFER)";
        if( !curl_setopt($ch, CURLOPT_FORBID_REUSE, false)) return "FAIL: curl_setopt(CURLOPT_FORBID_REUSE)";
        curl_setopt($ch, CURLOPT_USERAGENT, '"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.11) Gecko/20071204 Ubuntu/7.10 (gutsy) Firefox/2.0.0.11');
    }
      // if( !curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true) ) return "FAIL: curl_setopt(CURLOPT_FOLLOWLOCATION)";
      // if( !curl_setopt($ch, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)";
      // if( !curl_setopt($ch, CURLOPT_HEADER, 0) ) return "FAIL: curl_setopt(CURLOPT_HEADER)";
      if( !curl_exec($ch) ) return "FAIL: curl_exec()";
      curl_close($ch);
      fclose($fp);
      return "SUCCESS: $file [$url]";
    }
    else return "FAIL: fopen()";
  }
  else return "FAIL: curl_init()";
}
해설 (0)
  • &Amp php 4. 5 Solution:*

    • 대용량 파일 전송, readfile () 을 제시하지 않을 경우에도 메모리 문제에 대해서는 자체. 이 기능을 사용할 수 있는 경우 URL 로 파일_이름 fopen 래퍼 설정되었습니다.

http://php.net/manual/en/function.readfile.php

해설 (1)