Home > Backend Development > PHP Tutorial > 获取资料列表,点击文件名打开文件的方法,哪位有时间帮帮忙

获取资料列表,点击文件名打开文件的方法,哪位有时间帮帮忙

WBOY
Release: 2016-06-13 12:46:52
Original
895 people have browsed it

获取文件列表,点击文件名打开文件的方法,哪位有时间帮帮忙啊

左右两栏,左栏提取某目录下的所有HTML文件,鼠标点击文件名,可以在右栏显示点击的HTML文件<br />
这是HTML结构<br />
		<div id="sidebar"><br />
			<p>文件目录如下:</p><br />
			<div id="fileList"><br />
				<?php<br />
					getFile("要索引的目录路径");<br />
				?><br />
			</div><br />
		</div><br />
		<div id="main"><br />
			//此处显示点击的HTML文件<br />
            //echo openFile(就这里不会写);<br />
		</div><br />
<br />
	//获取文件列表函数<br />
	function getFile($dir) {<br />
	    $fileArray[]=NULL;<br />
	    if (false != ($handle = opendir ( $dir ))) {<br />
	        $i=0;<br />
	        while ( false !== ($file = readdir ( $handle )) ) {<br />
	            //去掉"“.”、“..”以及带“.xxx”后缀的文件<br />
	            if ($file != "." && $file != ".."&&strpos($file,".")) {<br />
	                $fileArray[$i]="".$file;<br />
	                if($i==100){<br />
	                    break;<br />
	                }<br />
	                $i++;<br />
	            }<br />
	        }<br />
	        //关闭句柄<br />
	        closedir ( $handle );<br />
	    }<br />
		foreach($fileArray as $value)<br />
		{<br />
			echo "<a href='".$value."'>".$value."</a>"; //这里输出数组内容<br />
			echo "<br/>";<br />
		}<br />
	    return $fileArray;<br />
	}<br />
	<br />
	//打开文件函数<br />
	function openFile($filename) <br />
	{    <br />
		$return = '';    <br />
		if ($fp = fopen($filename, 'rb')) <br />
		{      <br />
			while (!feof($fp))<br />
			{       <br />
				$return .= fread($fp, 1024);     <br />
			}      <br />
			fclose($fp);      <br />
			return $return;   <br />
		 } <br />
		else <br />
		{  <br />
			return false;    <br />
		}  <br />
	} <br />
[code=php]
Copy after login
[/code]

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template