博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP获取Linux当前目录下文件并实现下载功能
阅读量:6984 次
发布时间:2019-06-27

本文共 5047 字,大约阅读时间需要 16 分钟。

使用nginx转发过去给php

server{	listen 9099;	server_name 18.5.6.2;	location / {		proxy_http_version 1.1;		root /opt/zidian/crackPass;		index index.html index.htm index.php;	}	location ~* \.php$ {		root /opt/zidian/crackPass;		fastcgi_pass 127.0.0.1:9000;		fastcgi_index index.php;		fastcgi_param SCRIPT_FILENAME /opt/zidian/crackPass$fastcgi_script_name;		include fastcgi_params;	}}

server_name  公网ip

fastcgi_pass 127.0.0.1:9000   转发给php(使用netstat -tlnp | grep php看到php的端口是9000)

index.php

";header("Content-type: text/html; charset=utf-8");function getsize($size, $format = 'kb') { $p = 0; if ($format == 'kb') { $p = 1; } elseif ($format == 'mb') { $p = 2; } elseif ($format == 'gb') { $p = 3; } $size /= pow(1024, $p); return number_format($size, 3);}function read_all ($dir){ if(!is_dir($dir)) return false; $handle = opendir($dir); if($handle){ while(($fl = readdir($handle)) !== false){ $temp = iconv('utf-8','utf-8',$dir.DIRECTORY_SEPARATOR.$fl); if(is_dir($temp) && $fl!='.' && $fl != '..'){ #echo '目录:'.$temp.'
'; #read_all($temp); }else{ if($fl!='.' && $fl != '..'){ #echo $fl; #echo '文件:'.$temp.'
'; $cfiletime = filectime($fl); echo "文件:"; echo ""; echo "'$fl'"; echo ""; echo ""; $size = filesize($fl); $size = getsize($size, 'mb'); echo "容量:"; echo "$size.'M'"; echo ""; # echo "创建时间:"; # echo "" .date("Y-m-d H:i:s",$cfiletime); echo ""; echo "
"; } } } }}read_all('.');echo "
";echo "";echo "";echo "";#echo "";?>

index.php(2018-06-21)

";header("Content-type: text/html; charset=utf-8");echo "

";echo "夏天分享小知识";echo "

";ini_set('date.timezone','Asia/Shanghai');function getsize($size, $format = 'kb') { $p = 0; if ($format == 'kb') { $p = 1; } elseif ($format == 'mb') { $p = 2; } elseif ($format == 'gb') { $p = 3; } $size /= pow(1024, $p); return number_format($size, 3);}function read_all ($dir){ if(!is_dir($dir)) return false; $handle = opendir($dir); if($handle){ while(($fl = readdir($handle)) !== false){ $temp = iconv('utf-8','utf-8',$dir.DIRECTORY_SEPARATOR.$fl); if(is_dir($temp) && $fl!='.' && $fl != '..'){ #echo '目录:'.$temp.'
'; #read_all($temp); }else{ if($fl!='.' && $fl != '..'){ #echo $fl; #echo '文件:'.$temp.'
'; $cfiletime = filectime($fl); echo "
"; echo "
"; echo "
"; echo "
"; echo "
"; echo "文件:"; echo ""; echo "'$fl'"; echo ""; echo ""; $size = filesize($fl); $size = getsize($size, 'mb'); echo " "; echo "容量:"; echo "$size.'M'"; echo ""; echo " "; echo "修改时间:"; echo "" .date("Y-m-d H:i:s",$cfiletime); echo ""; echo "
"; echo "
"; } } } }}read_all('.');echo "
";echo "";echo "";echo "";echo " ";echo "";echo "";echo "";echo " ";echo "";echo "";echo "";echo " ";echo "";echo "";echo "";echo " ";echo "";echo "";echo "";#echo "";?>

返回(2018-06-21)

";header("Content-type: text/html; charset=utf-8");echo "

";echo "夏天分享小知识";echo "

";ini_set('date.timezone','Asia/Shanghai');function getsize($size, $format = 'kb') { $p = 0; if ($format == 'kb') { $p = 1; } elseif ($format == 'mb') { $p = 2; } elseif ($format == 'gb') { $p = 3; } $size /= pow(1024, $p); return number_format($size, 3);}function read_all ($dir){ if(!is_dir($dir)) return false; $handle = opendir($dir); if($handle){ while(($fl = readdir($handle)) !== false){ $temp = iconv('utf-8','utf-8',$dir.DIRECTORY_SEPARATOR.$fl); if(is_dir($temp) && $fl!='.' && $fl != '..'){ #echo '目录:'.$temp.'
'; #read_all($temp); }else{ if($fl!='.' && $fl != '..'){ #echo $fl; #echo '文件:'.$temp.'
'; $cfiletime = filectime($fl); $mfiletime = filemtime($fl); echo "
"; echo "
"; echo "
"; echo "
"; echo "
"; echo "文件:"; echo ""; echo "'$fl'"; echo ""; echo ""; $size = filesize($fl); $size = getsize($size, 'mb'); echo " "; echo "容量:"; echo "$size.'M'"; echo ""; echo " "; echo "修改时间:"; echo "".date("Y-m-d H:i:s",$cfiletime); echo ""; #echo "创建时间:".date("Y-m-d H:i:s",$cfiletime); #echo "修改时间:".date("Y-m-d H:i:s",$mfiletime); echo "
"; echo "
"; } } } }}read_all('.');echo "
";echo "";echo "";echo "";#echo "";?>

作用:点击链接实现下载文件

 

转载于:https://www.cnblogs.com/chenglee/p/9143399.html

你可能感兴趣的文章
PHP案例 网页计数器设计
查看>>
算出两个经纬度的距离(米)
查看>>
我的友情链接
查看>>
树莓派2代B model 上手初体验,不用显示器,Python GPIO 点亮一颗LED
查看>>
114DNS Public DNS+ 阿里DNS 百度DNS 360 DNS派 Google DNS公共DNS评测体验报告
查看>>
[SOJ]连通性问题
查看>>
SpringMVC日期类型转换问题三大处理方法归纳
查看>>
javascript6
查看>>
lnmp 一键安装包部署ThinkPHP5
查看>>
Linux下升级安装Python-2.7.8版本
查看>>
3.无重复字符的最长字串
查看>>
WPF入门(一)——绑定Binding
查看>>
一些常见的配置
查看>>
浏览器外部署Silverlight更新检查失败的原因及对策
查看>>
PHP正则表达式——匹配多行
查看>>
react native中一次错误排查 Error:Error: Duplicate resources
查看>>
Kotlin 4 构造,对象,修饰符,关键字,委托
查看>>
ios改变字体
查看>>
Android的ClassLoader知多少
查看>>
"愿有人陪你颠沛流离|Be With You"
查看>>