1:file_get_contents,file_put_contents方式
<?php function download_remote_file($file_url, $save_to) { $content = file_get_contents($file_url); file_put_contents($save_to, $content); }?>用法:
<?php download_remote_file('http://www.54ux.com/wp-content/themes/d-simple/img/thumbnail.jpg', realpath("./downloads") . '/file.jpg');?>2:curl方式
function download_remote_file_with_curl($file_url, $save_to) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch,CURLOPT_URL,$file_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $file_content = curl_exec($ch); curl_close($ch); $downloaded_file = fopen($save_to, 'w'); fwrite($downloaded_file, $file_content); fclose($downloaded_file); }用法:
<?php download_remote_file_with_curl('http://www.54ux.com/wp-content/themes/d-simple/img/thumbnail.jpg', realpath("./downloads") . '/file.jpg');?>3:fopen方法
远航CMS(yhcms)是一套基于PHP+MYSQL为核心开发的专业营销型企业建站系统。是国内首家免费+开源自带分站系统的php内容管理系统。长期以来不断的完善、创新,远航CMS会为您带来全新的体验!产品十大优势:模板分离:模板程序分离,深度二次开发三网合一:电脑/手机/微信 多终端访问自定义广告:图片/文字/动画定时发布:SEO维护,无需人工值守多词生成:栏目关键词多方案生成SEO设置:自定义U
1
立即学习“PHP免费学习笔记(深入)”;
function download_remote_file_with_fopen($file_url, $save_to) { $in= fopen($file_url, "rb"); $out= fopen($save_to, "wb"); while ($chunk = fread($in,8192)) { fwrite($out, $chunk, 8192); } fclose($in); fclose($out); }用法:
<?php download_remote_file_with_fopen('http://www.54ux.com/wp-content/themes/d-simple/img/thumbnail.jpg', realpath("./downloads") . '/file.jpg');?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号