用iframe指到非htdocs文件夹以外的文件 PHP 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不在 web 服务器管理范围的文件,就不能用 http 协议访问你需要通过 php 程序中转 哪到底该如何做呢? 我的filelist页码是可以指到任何文件夹的。是否可以修改成嵌入文件打开呢? 页码如下:<?phperror_reporting(0);$basedir = "c:/filelist";if(!is_dir($basedir)) $basedir = dirname(__FILE__);$file_name = $_GET['downfile'];if(!empty($file_name)){$file_dir = $basedir . "/" . $file_name;if(dirname(realpath($file_dir)) < $basedir){echo "Permission Denied!";exit;}if (!file_exists($file_dir)) {echo "File Not Found!";exit;} else {$file = fopen($file_dir,"r");Header("Content-type: application/octet-stream");Header("Accept-Ranges: bytes");Header("Accept-Length: ".filesize($file_dir));Header("Content-Disposition: attachment; filename=" . $file_name);echo fread($file,filesize($file_dir));fclose($file);exit;}}header("Content-type: text/html; charset=utf-8");$requestDir = $_GET['dir'];if(empty($requestDir)){$dir = $basedir;}else{$dir = $basedir . "/" . $requestDir;}$dir = realpath($dir);if($dir < $basedir) $dir = $basedir;?><html><head><title>File Listing</title><STYLE type="text/css">body {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;}td {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;}input {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;}.title {font-family: "Verdana", "Tahoma";font-size: 22px;font-weight: bold;}</STYLE></head><body><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td class="title">File Listing</td><td align="right" valign="bottom"><font color="#FF0000"><h2><a href="logout.php">Sign Out</a></h2></font></td></tr></table><hr width="100%" style="border:1px dashed black; height:1px"><table width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td><?php $predir = realpath($dir . "/../");if($predir > $basedir) $predir = str_replace($basedir . "/","",$predir);if($predir == $basedir) $predir = ".";if($dir > $basedir) echo "<a href=\"?dir=". $predir ."\">Up Level</a>";?></td></tr><?php$dirs=@opendir($dir);$count = 0;while($file=@readdir($dirs)) {$b="$dir/$file";$a=@is_dir($b);if($a=="1"){if($file!=".."&&$file!=".") {if($count < 1){$count ++;echo "<tr>\n";echo "<td><b>Folder</b></td>\n";echo "</tr>\n";}echo "<tr>\n";echo "<td><a href=\"?dir=" . ($dir > $basedir ? str_replace($basedir . "/",'',$dir . "/") : '') . urlencode($file)."\">$file</a></td>\n";echo "</tr>\n";}}}@closedir($dirs);?></table><hr width="100%" style="border:1px dashed black; height:1px"><table width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td><b>Filename</b></td><td><b>Date</b></td><td><b>Size</b></td><td><b>Action</b></td></tr><?php$dirs=@opendir($dir);while ($file=@readdir($dirs)) {$b="$dir/$file";$a=@is_dir($b);if($a=="0"){$size=@filesize("$dir/$file");$size=$size/1024 ;$size= @number_format($size,2);$lastsave=@date("Y-n-d H:i:s",filemtime("$dir/$file"));echo "<tr>\n";echo "<td>$file</td>\n";echo "<td>$lastsave</td>\n";echo "<td>$size KB</td>\n";echo "<td><a href=\"?downfile=".($dir > $basedir ? str_replace($basedir . "/",'',$dir . "/") : '').urlencode($file)."\">Download</a></td>\n";echo "</tr>\n";}}@closedir($dirs);?></table><hr width="100%" style="border:1px dashed black; height:1px"><?php include View::getView('side'); include View::getView('footer');?> 已解决,用以下的代码即可。<?php $file_handle = fopen("outsidefile/file.txt", "r");while (!feof($file_handle)) {$line_of_text = fgets($file_handle);print $line_of_text . "<BR>";}fclose($file_handle); ?> PHP 生成缩略图片的问题 php中的错误日志怎么处理啊 求点ZendStudio-7.0.0-EA与appserv 2.0的配置资料? 具备什么条件才能读懂DedeCMS或PHPCMS的源码? 请教一个问题! 大家好!今天我在安装window2003 中安装时遇到不能显示的问题?有谁能帮帮忙?谢谢 关于php定制导航 并生成链接 别人可以访问 哪里能下载PHP 4.0时尚编程百例 请问PHP如何在登陆验证成功后跳转到登陆前访问的页面 php导出csv文件用excel 2003打开乱码 php编码转化 一个正则匹配的问题
你需要通过 php 程序中转
$basedir = "c:/filelist";
if(!is_dir($basedir)) $basedir = dirname(__FILE__);
$file_name = $_GET['downfile'];
if(!empty($file_name)){$file_dir = $basedir . "/" . $file_name;if(dirname(realpath($file_dir)) < $basedir){echo "Permission Denied!";exit;}if (!file_exists($file_dir)) {echo "File Not Found!";exit;} else {$file = fopen($file_dir,"r");Header("Content-type: application/octet-stream");Header("Accept-Ranges: bytes");Header("Accept-Length: ".filesize($file_dir));Header("Content-Disposition: attachment; filename=" . $file_name);echo fread($file,filesize($file_dir));fclose($file);exit;}
}
header("Content-type: text/html; charset=utf-8");
$requestDir = $_GET['dir'];
if(empty($requestDir)){$dir = $basedir;
}else{$dir = $basedir . "/" . $requestDir;
}
$dir = realpath($dir);
if($dir < $basedir) $dir = $basedir;
?><html>
<head>
<title>File Listing</title>
<STYLE type="text/css">
body {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;
}td {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;
}input {font-family: "Courier New", "Verdana", "Tahoma";font-size: 12px;
}.title {font-family: "Verdana", "Tahoma";font-size: 22px;font-weight: bold;
}
</STYLE>
</head>
<body><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td class="title">File Listing</td><td align="right" valign="bottom"><font color="#FF0000"><h2><a href="logout.php">Sign Out</a></h2></font></td></tr></table><hr width="100%" style="border:1px dashed black; height:1px"><table width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td><?php $predir = realpath($dir . "/../");if($predir > $basedir) $predir = str_replace($basedir . "/","",$predir);if($predir == $basedir) $predir = ".";if($dir > $basedir) echo "<a href=\"?dir=". $predir ."\">Up Level</a>";?></td></tr><?php$dirs=@opendir($dir);$count = 0;while($file=@readdir($dirs)) {$b="$dir/$file";$a=@is_dir($b);if($a=="1"){if($file!=".."&&$file!=".") {if($count < 1){$count ++;echo "<tr>\n";echo "<td><b>Folder</b></td>\n";echo "</tr>\n";}echo "<tr>\n";echo "<td><a href=\"?dir=" . ($dir > $basedir ? str_replace($basedir . "/",'',$dir . "/") : '') . urlencode($file)."\">$file</a></td>\n";echo "</tr>\n";}}}@closedir($dirs);?></table><hr width="100%" style="border:1px dashed black; height:1px"><table width="100%" border="0" cellpadding="3" cellspacing="1"><tr><td><b>Filename</b></td><td><b>Date</b></td><td><b>Size</b></td><td><b>Action</b></td></tr><?php$dirs=@opendir($dir);while ($file=@readdir($dirs)) {$b="$dir/$file";$a=@is_dir($b);if($a=="0"){$size=@filesize("$dir/$file");$size=$size/1024 ;$size= @number_format($size,2);$lastsave=@date("Y-n-d H:i:s",filemtime("$dir/$file"));echo "<tr>\n";echo "<td>$file</td>\n";echo "<td>$lastsave</td>\n";echo "<td>$size KB</td>\n";echo "<td><a href=\"?downfile=".($dir > $basedir ? str_replace($basedir . "/",'',$dir . "/") : '').urlencode($file)."\">Download</a></td>\n";echo "</tr>\n";}}@closedir($dirs);?></table>
<hr width="100%" style="border:1px dashed black; height:1px">
<?php include View::getView('side'); include View::getView('footer');?>
print $line_of_text . "<BR>";}fclose($file_handle);
?>