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

PHP下载文件函数

WBOY
Release: 2016-06-23 14:28:47
Original
1007 people have browsed it

一个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);
    }
?>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template