Home >Backend Development >PHP Tutorial >PHP下载文件函数

PHP下载文件函数

WBOY
WBOYOriginal
2016-06-23 14:28:47987browse

一个PHP下载函数,在写服务器的时候可以用到。

        

        

        
        
        
        
        
        
        
        
        
    set_time_limit( 24 * 60 * 60);
    if ( ! isset( $_POST [ 'submit' ])) die ();
    $destination_folder = './down/';   // 文件夹保存下载文件。必须以斜杠结尾
    $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);
    }
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP日期检查函数Next article:Google App Engine上运行PHP