Home > Backend Development > PHP Tutorial > PHP 远程下载文件不完整

PHP 远程下载文件不完整

WBOY
Release: 2016-06-06 20:23:35
Original
1638 people have browsed it

方法是 remote_file()

<code>if(! function_exists('remote_file')) {
    
    function remote_file($url = '', $filename = '') {
        //set_time_limit(0);
        if(! $url) {
            return false;
        }
        if(!file_exists('../static/porn/') && !mkdir('../static/porn/', 0777, true)) {
            return false;
        }
        
        $ext = strrchr($url, ".");
        
        if(! $filename) {
            $filename = time() . $ext;
        }
        
        ob_start();
        readdir($url);
        $content = ob_get_contents();
        ob_end_clean();
        $size = strlen($content);
        $fp2 = @fopen('../static/porn/'.$filename, 'a');
        fwrite($fp2, $content);
        fclose($fp2);
        return config_item('static_site')."porn/{$filename}";
    }
}</code>
Copy after login
Copy after login

回复内容:

方法是 remote_file()

<code>if(! function_exists('remote_file')) {
    
    function remote_file($url = '', $filename = '') {
        //set_time_limit(0);
        if(! $url) {
            return false;
        }
        if(!file_exists('../static/porn/') && !mkdir('../static/porn/', 0777, true)) {
            return false;
        }
        
        $ext = strrchr($url, ".");
        
        if(! $filename) {
            $filename = time() . $ext;
        }
        
        ob_start();
        readdir($url);
        $content = ob_get_contents();
        ob_end_clean();
        $size = strlen($content);
        $fp2 = @fopen('../static/porn/'.$filename, 'a');
        fwrite($fp2, $content);
        fclose($fp2);
        return config_item('static_site')."porn/{$filename}";
    }
}</code>
Copy after login
Copy after login

有些服务器环境会禁用掉readdir的,要么就是文件太大超时了。或者你试试输出错误看看

Related labels:
php
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