Home > php教程 > php手册 > body text

php实现图片远程下载(PHP100论坛)

WBOY
Release: 2016-06-21 08:50:18
Original
1064 people have browsed it

     $pic=$matche_pic[1][0];//远程文件路径
        $data = file_get_contents($pic); // 读文件内容 
        $filetime = time(); //得到时间戳
        $filepath = $_SERVER['DOCUMENT_ROOT']."public/".date("Ym",$filetime)."/";//图片保存的路径目录 
        if(!is_dir($filepath)){
            mkdir($filepath,0777, true);
        }
        $filename = date("YmdHis",$filetime).rand(100,999).'.'.substr($pic,-3,3); //生成文件名,
        $fp = @fopen($filepath.$filename,"w"); //以写方式打开文件
        @fwrite($fp,$data); //
        fclose($fp);//完工,哈



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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!