php - 使用php在服务器之间传输文件

标签 php

Hello
I wrote a little code in php that enables me to download a file from one
 website to my own!
but there is a little problem here!
I can only Download files from my website that are less than 4MB:(
Now my question is that in what way I can Download special 
part of files from other websites!
like from 1st byte to 10th byte!

And second question is how to get file 
Information before starting Download!
(I want files size for downloading)

http://www.polarpengi.gigfa.com/code.htm

最佳答案

function downloadFileFromUrl($url, $dstFilepath) {
    $fr = @fopen($url, 'r');
    if($fr === false) {
        throw new Primage_Proxy_Storage_SourceNotFound($url);
    }
    $fw = fopen($dstFilepath, 'w');
    if($fw === false) {
        throw new Exception('Writing to file "' . $dstFilepath . '" failed');
    }

    $timeLimit = 1000;
    set_time_limit($timeLimit);
    $deadline = time() + 1000;

    while(!feof($fr)) {
        $bufferString = fread($fr, 10000);
        fwrite($fw, $bufferString);
        if($deadline - time() < 10) {
            fclose($fw);
            fclose($fr);
            unlink($dstFilepath);
            throw new Primage_Proxy_Storage_SourceNotFound($url);
        }
    }
    fclose($fw);
    fclose($fr);
}

关于php - 使用php在服务器之间传输文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3939532/

相关文章:

php - Laravel 5.2 中无法与主机 smtp.gmail.com 建立连接 [连接超时 #110]

php - 跳过别名中的某些号码

php - 从 dovecot/postfix 上的 php 脚本创建一个新的电子邮件帐户

PHP/MySQL 一个数组中包含两行

php - 如何在Mysql字段中设置默认当前日期时间

php - 使用PHP;我想检查 mysql 数据库以确保在注册之前没有相同电子邮件地址的记录

php - Paypal API/SDK 计费计划和协议(protocol)

javascript函数只传递一个特定参数

javascript - 单击图片打开文件上传对话框

php - 有没有办法使用 PHP 而不是使用 mssql_pconnect() 将 MySQL 连接到 SQL DB?