php下载文件,线上文件下载

1.多个文件下载

<?php
/* 把知道的图片问题名字做成一个数组 */
$mp4 = ['123','456'];
/* count($mp4) 类似于 js 的 $mp4.length */
for ($i=1; $i<=count($mp4); $i++){
/* 线上的资源文件 */
$url='https://'. $mp4[$i-1] .'.mp4';
/* file_get_contents函数是用于将文件的内容读入到一个字符串中的首选方法 */
$content=file_get_contents($url);
if($content){
/* 写入自己的文件夹里面 /是用于转义 */
file_put_contents('C:\Users\n0209\Desktop\images\/'. $mp4[$i-1] .'.mp4',$content);
echo $i.'写入成功';
}else{
echo $i.'写入失败';
}
}
?>

2.单个文件下载

<?php
/* 线上的文件资源链接 */
$url='https://123.jpg';
/* file_get_contents函数是用于将文件的内容读入到一个字符串中的首选方法 */
$content=file_get_contents($url);
if($content){
/* 写入自己的文件夹里面 文件名字可以在这里定义 */
file_put_contents('C:\Users\n0209\Desktop\images\123.jpg',$content);
echo $i.'写入成功';
}else{
echo $i.'写入失败';
}
?>

 

posted @ 2019-10-29 11:15  幻景  阅读(272)  评论(0编辑  收藏  举报