php实现扫描附件的功能,并判断是否是目录,递归访问目录,返回上一层目录功能的实现
来源:互联网 发布:西安交大网络教育官网 编辑:程序博客网 时间:2024/05/15 23:53
php实现扫描附件的功能,并判断是否是目录,递归访问目录,返回上一层目录功能的实现
功能描述:
我们在做选择附件上传的时候,可能选择在项目中已经上传过的附件,这样我们就需要扫描文件,选择指定文件并上传。
demo入口代码如下:
~~ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
~~ <html>
~~ <head>
~~ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
~~ <title>文件列表的扫描</title>
~~ <script type="text/javascript" src="./jquery-1.7.1.js"></script>
~~ </head>
~~ <body>
~~
~~ <p>上传文件</p>
~~ <input name='filepath' value='' id='filepath' size='50'/><a href='javascript:;' onclick='selectImage(this)'>浏览</a>
~~ <script type="text/javascript">
~~ function selectImage(e){
~~ var xx = e.pageX || 0;
~~ var yy = e.pageY || 0;
~~ if(xx !=0 && yy !=0 ){
~~ posLeft = xx-100;
~~ posTop = yy;
~~ }else{ var posLeft = 100; var posTop = 100; }
~~ //if(!fname) fname = 'form1.picname';
~~ //if(!stype) stype = '';
~~ window.open("./select_images.php", "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=600,height=400,left="+posLeft+", top="+posTop);
~~ }
~~ </script>
~~ </body>
~~ </html>
核心代码的实现代码如下:
~~ <?php
~~ /**
~~ * 文件的扫描
~~ *
~~ */
~~ //文件的存放地址
~~ $uploadPath = dirname(__FILE__) . DIRECTORY_SEPARATOR;
~~ //请求的目录地址
~~ $_GET['activepath'] = isset( $_GET['activepath'] ) ? urldecode($_GET['activepath']) : "";
~~ $activepath = ( isset( $_GET['activepath'] ) && ( trim($_GET['activepath']) ) ) ? trim( $_GET['activepath'] ) : 'upload';
~~
~~ $fileList = scanDirList($uploadPath,$activepath );
~~
~~ //上一级目录
~~ if( $activepath != "" && $activepath != "upload" ){
~~ $preDir = substr( dirname( $uploadPath.$activepath ),strlen( $uploadPath ) );
~~ }else{
~~ $preDir = $activepath;
~~ }
~~ $preDir = urlencode( $preDir );
~~
~~
~~ //文件列表的输出
~~ $fileTrHtml = '';
~~
~~ foreach( $fileList as $k=>$v ){
~~
~~ $fileTrHtml .= "<tr><td>".($v['isdir']==1 ? '【目录】' : '【文件】' );
~~
~~ if( $v['isdir']== 1){
~~ $v['path'] = urlencode( $v['path'] );
~~ $fileTrHtml .= "<a href='./select_images.php?activepath={$v['path']}'>{$v['name']}</a>";
~~
~~ }else{
~~
~~ $fileTrHtml .= "<a href='javascript:;' onclick=\"setImageUrl('{$v['path']}')\">{$v['name']}</a>";
~~
~~ }
~~
~~
~~ $fileTrHtml .= "</td></tr>";
~~ }
~~
~~
~~
~~ $html = <<<EOT
~~ <html>
~~ <head></head>
~~ <body>
~~
~~ <div>
~~ <table>
~~ <tr>
~~ <td><a href="./select_images.php?activepath={$preDir}">返回上一级目录</a> 当前目录{$activepath}</td>
~~ </tr>
~~ {$fileTrHtml}
~~ </table>
~~ </div>
~~ <script type='text/javascript'>
~~ function setImageUrl( imgurl ){
~~ window.opener.document.getElementById('filepath').value = imgurl;
~~ if(document.all) window.opener=true;
~~ window.close();
~~ }
~~ </script>
~~ </body>
~~ </html>
~~ EOT;
~~
~~ echo $html;
~~
~~
~~ /**
~~ *
~~ * @param $uploadPath 文件存储根目录
~~ * @param $activepath 需要扫描的问了名称
~~ */
~~ function scanDirList($uploadPath,$activepath){
~~ $file_array = array();
~~ $path = $uploadPath.$activepath;
~~ if ($handle = @opendir($path)) {
~~ while (false !== ($file = @readdir($handle))) {
~~ if($file=='.' || $file=='..'){
~~ continue;
~~ }
~~ $filePath = $activepath."/".$file;
~~ $temp['name'] = $file;
~~ $temp['path'] = $filePath;
~~ if(is_dir($filePath)){
~~ $temp['isdir'] = 1;
~~ }else{
~~ $temp['isdir'] = 0;
~~ }
~~ $file_array[] = $temp;
~~ }
~~ @closedir($handle);
~~ }
~~ return $file_array;
~~ }
~~
~~
~~ ?>
demo托管地址:[https://github.com/abaiweb/file]
功能描述:
我们在做选择附件上传的时候,可能选择在项目中已经上传过的附件,这样我们就需要扫描文件,选择指定文件并上传。
demo入口代码如下:
~~ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
~~ <html>
~~ <head>
~~ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
~~ <title>文件列表的扫描</title>
~~ <script type="text/javascript" src="./jquery-1.7.1.js"></script>
~~ </head>
~~ <body>
~~
~~ <p>上传文件</p>
~~ <input name='filepath' value='' id='filepath' size='50'/><a href='javascript:;' onclick='selectImage(this)'>浏览</a>
~~ <script type="text/javascript">
~~ function selectImage(e){
~~ var xx = e.pageX || 0;
~~ var yy = e.pageY || 0;
~~ if(xx !=0 && yy !=0 ){
~~ posLeft = xx-100;
~~ posTop = yy;
~~ }else{ var posLeft = 100; var posTop = 100; }
~~ //if(!fname) fname = 'form1.picname';
~~ //if(!stype) stype = '';
~~ window.open("./select_images.php", "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=600,height=400,left="+posLeft+", top="+posTop);
~~ }
~~ </script>
~~ </body>
~~ </html>
核心代码的实现代码如下:
~~ <?php
~~ /**
~~ * 文件的扫描
~~ *
~~ */
~~ //文件的存放地址
~~ $uploadPath = dirname(__FILE__) . DIRECTORY_SEPARATOR;
~~ //请求的目录地址
~~ $_GET['activepath'] = isset( $_GET['activepath'] ) ? urldecode($_GET['activepath']) : "";
~~ $activepath = ( isset( $_GET['activepath'] ) && ( trim($_GET['activepath']) ) ) ? trim( $_GET['activepath'] ) : 'upload';
~~
~~ $fileList = scanDirList($uploadPath,$activepath );
~~
~~ //上一级目录
~~ if( $activepath != "" && $activepath != "upload" ){
~~ $preDir = substr( dirname( $uploadPath.$activepath ),strlen( $uploadPath ) );
~~ }else{
~~ $preDir = $activepath;
~~ }
~~ $preDir = urlencode( $preDir );
~~
~~
~~ //文件列表的输出
~~ $fileTrHtml = '';
~~
~~ foreach( $fileList as $k=>$v ){
~~
~~ $fileTrHtml .= "<tr><td>".($v['isdir']==1 ? '【目录】' : '【文件】' );
~~
~~ if( $v['isdir']== 1){
~~ $v['path'] = urlencode( $v['path'] );
~~ $fileTrHtml .= "<a href='./select_images.php?activepath={$v['path']}'>{$v['name']}</a>";
~~
~~ }else{
~~
~~ $fileTrHtml .= "<a href='javascript:;' onclick=\"setImageUrl('{$v['path']}')\">{$v['name']}</a>";
~~
~~ }
~~
~~
~~ $fileTrHtml .= "</td></tr>";
~~ }
~~
~~
~~
~~ $html = <<<EOT
~~ <html>
~~ <head></head>
~~ <body>
~~
~~ <div>
~~ <table>
~~ <tr>
~~ <td><a href="./select_images.php?activepath={$preDir}">返回上一级目录</a> 当前目录{$activepath}</td>
~~ </tr>
~~ {$fileTrHtml}
~~ </table>
~~ </div>
~~ <script type='text/javascript'>
~~ function setImageUrl( imgurl ){
~~ window.opener.document.getElementById('filepath').value = imgurl;
~~ if(document.all) window.opener=true;
~~ window.close();
~~ }
~~ </script>
~~ </body>
~~ </html>
~~ EOT;
~~
~~ echo $html;
~~
~~
~~ /**
~~ *
~~ * @param $uploadPath 文件存储根目录
~~ * @param $activepath 需要扫描的问了名称
~~ */
~~ function scanDirList($uploadPath,$activepath){
~~ $file_array = array();
~~ $path = $uploadPath.$activepath;
~~ if ($handle = @opendir($path)) {
~~ while (false !== ($file = @readdir($handle))) {
~~ if($file=='.' || $file=='..'){
~~ continue;
~~ }
~~ $filePath = $activepath."/".$file;
~~ $temp['name'] = $file;
~~ $temp['path'] = $filePath;
~~ if(is_dir($filePath)){
~~ $temp['isdir'] = 1;
~~ }else{
~~ $temp['isdir'] = 0;
~~ }
~~ $file_array[] = $temp;
~~ }
~~ @closedir($handle);
~~ }
~~ return $file_array;
~~ }
~~
~~
~~ ?>
demo托管地址:[https://github.com/abaiweb/file]
0 0
- php实现扫描附件的功能,并判断是否是目录,递归访问目录,返回上一层目录功能的实现
- php 模拟返回url上一层目录
- 目录扫描的实现
- php实现目录下的文件读取功能
- PHP下载功能的实现和获得当前目录
- docker1.9目录结构及各目录实现的功能
- 实现的小功能:判断报名是否重复,是返回true,否返回false.
- Linux返回上一次访问的目录
- Minifilter过滤,功能实现对驱动目录的监控,包括创建,重命名,删除并实现hips
- 如何实现访问apache时的目录浏览功能(apache file list view)
- (八)linux下编程实现ls功能的打开、访问 、关闭目录以及提取属性。
- linux下目录扫描的实现
- C语言如何实现遍历目录的功能
- [common-sln]: base工程增加遍历目录的功能实现
- 利用boost.filesystem实现跨平台的复制目录功能
- jsp页面中实现目录树的功能
- JS 实现遍历某一磁盘文件夹下目录的功能
- php创建目录功能
- g++/gcc 常见选项。(muduo 编译小程序举例)
- Redis之消息通讯测试
- Yahoo军规34(转载)
- android的fragment使用中static静态fragment实例遇到的坑
- 环信tokey转字符串
- php实现扫描附件的功能,并判断是否是目录,递归访问目录,返回上一层目录功能的实现
- 语法杂项技术小结
- 找出字符串
- struts2中常用Result类型type的用法
- new和alloc init的区别
- android 购物车 listview嵌套问题
- com.mysql.jdbc.PacketTooBigException 问题解决
- SCU 4515 又见背包(dp)
- 用boost::lexical_cast进行数值转换