نمایش نتایج: از شماره 1 تا 10 , از مجموع 12

موضوع: *ضروری*درخواست راهنمائی برای انتقال یک فایل بین دو اکانت در یک سرور

Threaded View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #10
    عضو دائم Rezash آواتار ها
    تاریخ عضویت
    Feb 2010
    محل سکونت
    مشهد
    نوشته ها
    1,923
    تشکر تشکر کرده 
    889
    تشکر تشکر شده 
    2,385
    تشکر شده در
    1,535 پست

    پیش فرض پاسخ : *ضروری*درخواست راهنمائی برای انتقال یک فایل بین دو اکانت در یک سرور

    کد PHP:
    /**
     * Copy remote file over HTTP one small chunk at a time.
     *
     * @param $infile The full URL to the remote file
     * @param $outfile The path where to save the file
     */
    function copyfile_chunked($infile$outfile) {
        
    $chunksize 10 * (1024 1024); // 10 Megs

        /**
         * parse_url breaks a part a URL into it's parts, i.e. host, path,
         * query string, etc.
         */
        
    $parts parse_url($infile);
        
    $i_handle fsockopen($parts['host'], 80$errstr$errcode5);
        
    $o_handle fopen($outfile'wb');

        if (
    $i_handle == false || $o_handle == false) {
            return 
    false;
        }

        if (!empty(
    $parts['query'])) {
            
    $parts['path'] .= '?' $parts['query'];
        }

        
    /**
         * Send the request to the server for the file
         */
        
    $request "GET {$parts['path']} HTTP/1.1\r\n";
        
    $request .= "Host: {$parts['host']}\r\n";
        
    $request .= "User-Agent: Mozilla/5.0\r\n";
        
    $request .= "Keep-Alive: 115\r\n";
        
    $request .= "Connection: keep-alive\r\n\r\n";
        
    fwrite($i_handle$request);

        
    /**
         * Now read the headers from the remote server. We'll need
         * to get the content length.
         */
        
    $headers = array();
        while(!
    feof($i_handle)) {
            
    $line fgets($i_handle);
            if (
    $line == "\r\n") break;
            
    $headers[] = $line;
        }

        
    /**
         * Look for the Content-Length header, and get the size
         * of the remote file.
         */
        
    $length 0;
        foreach(
    $headers as $header) {
            if (
    stripos($header'Content-Length:') === 0) {
                
    $length = (int)str_replace('Content-Length: '''$header);
                break;
            }
        }

        
    /**
         * Start reading in the remote file, and writing it to the
         * local file one chunk at a time.
         */
        
    $cnt 0;
        while(!
    feof($i_handle)) {
            
    $buf '';
            
    $buf fread($i_handle$chunksize);
            
    $bytes fwrite($o_handle$buf);
            if (
    $bytes == false) {
                return 
    false;
            }
            
    $cnt += $bytes;

            
    /**
             * We're done reading when we've reached the conent length
             */
            
    if ($cnt >= $length) break;
        }

        
    fclose($i_handle);
        
    fclose($o_handle);
        return 
    $cnt;

    استفاده :
    کد PHP:
    copyfile_chunked('http://somesite.com/somefile.jpg''/local/path/somefile.jpg'); 
    منبع :
    http://stackoverflow.com/questions/4...w-memory-usage
    اینم خوبه :
    http://stackoverflow.com/a/6409494
    ویرایش توسط Rezash : June 3rd, 2016 در ساعت 11:51
    بک آپ بگیرید قبل از آنکه پشیمان شوید!
    تشخیص سیستم مدیریت محتوای سایت - سایت شخصی

اطلاعات موضوع

کاربرانی که در حال مشاهده این موضوع هستند

در حال حاضر 1 کاربر در حال مشاهده این موضوع است. (0 کاربران و 1 مهمان ها)

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •