[英]display html files based on the filename by searching it from the server
這對我來說有點復雜:例如說我的服務器有1200個文件:
file:///D:/xampp/htdocs/bibek/address/WRTRThu-05-Jul-2012-14-02-14pm.html
file:///D:/xampp/htdocs/bibek/address/WRTRThu-05-Jul-2012-13-02-23pm.html
file:///D:/xampp/htdocs/bibek/address/BRTRThu-05-Jul-2012-13-05-35pm.html
file:///D:/xampp/htdocs/bibek/address/BRTRThu-05-Jul-2012-12-06-52pm.html
等
可以看到它們每個都有一個名稱:WRTR和BRTR以及日期和時間。 我必須用php mysql javascript編寫腳本(只有在萬不得已時才可以使用),讓用戶輸入日期,時間和名稱(wrtr或brtr),他將能夠查看相應的文件。 有人可以建議如何進行嗎?
根據建議,並在maxhud的幫助下,我明白了,向您致敬...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function showFile(){
var name = document.getElementById("name").value;
var dday = document.getElementById("dday").value;
var month = document.getElementById("month").value;
var year = document.getElementById("year").value;
var hour =document.getElementById("hour").value;
var minute = document.getElementById("minute").value;
var second = document.getElementById("second").value;
var ofday = document.getElementById("ofday").value;
var day = document.getElementById("day").value;
var ofday=document.getElementById("ofday").value;
window.location = "address/" + name + day + "-" + dday+ "-" + month + "-" + year + "-" +hour + "-" + minute + "-" + second + ofday + ".html";
}
</script>
</head>
<body>
Name: <input id="name" placeholder="accountname"/><br/>
Date: <input id="dday" placeholder="01-31"/> - <input id="month" placeholder="month"/> - <input id="year" placeholder="year"/><br/><br/>
Time: <input id="hour" placeholder="24hours"/> - <input id="minute" placeholder="minute"> - <input id="second" placeholder="second"/>
of Day <input id="ofday" placeholder="am/pm"/>
<br/><br/>
Day: <input id="day"/>
<br/><br/>
<button onclick="showFile()">Take me to the file</button>
</body>
</html>
和php腳本:fileLocator2.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ethernet database check</title>
<style type="text/css">
body
{
width:90%;
max-height:auto;
min-height:600px;
background-color:#000;
color:white;
font-size:17px;
}
br{
margin-bottom:1em;
}
#textleft
{
float:left;
text-align:left;
}
#textright
{
float:right;
margin-right:2em;
}
.inputcont{
float:left;
width:20%;
margin-left:0.1em;
autofocus:autofocus;
}
a:link
{
text-decoration:none;
color:white;
}
title
{
border-radius:5px;
font-size:3em;
background-color:blue;
color:white;
}
.yellobutton
{
background-color:yellow;
margin-top:1%;
float:right;
margin-right:2%;
width:10em;
height:2.4em;
border:1px solid blue;
border:inset 1px solid black;
box-shadow:2px 2px 5px #fff;
color:black;
font-weight:bold;
}
</style>
</head>
<body>
<header style="height:4em;font-size:2em;"> Employee Access Only</header>
<div style="margin:2em;padding:1em 1em 4em 1em;height:auto;border:1px solid #000;border-radius:5px;-moz-box-shadow:0 0 5px 2px #ddb;box-shadow:0 0 5px 2px #ddd;">
<form method="POST" action="confirm.php">
<div id="textleft">Path or folder:<br></div>
<div id="textright"> <input id="path" name="path" placeholder="address no/"/>[?]</div><br/>
<div id="textleft">Name of file:<br/></div>
<div id="textright"> <input id="name" name="name" placeholder="filename"/><a href="#" title="WRTR BRTR">[?]</a></div><br/>
<div id="textleft">Day:<br/></div>
<div id="textright"> <input id="day" name="day"/><a href="#" title="Mon Tue Wed Thu Fri Sat">[?]</a></div>
<br/>
<div id="textleft">Date:</div>
<div id="textright"><input id="ddate" placeholder="01-31" name="ddate"/> - <input id="month" placeholder="month" name="month"/> - <input id="year" placeholder="2001-2011" name="year"/><a href="#" title="date:01-02-03..31 month:Jan,Feb,Mar,Apr,May,Jun,Jul,Aug year:2001...2011">[?]</a></div><br/>
<div id="textleft">Time:<br/></div>
<div id="textright"><input id="time" name="time"/><a href="#" title="hours-mins-seconds 13-20-23">[?]</a></div></br>
<input type="submit" class="yellobutton" id="submit" name="submit" value="show me"/>
</form>
</div>
<footer style="font-size:1.4em ;margin-top:20%;">©Bibek Agarwal Scripts</footer>
</body>
</html>
並確認
<?php
if(isset($_POST['submit']))
{
$pathfolder=trim($_POST['path']);
$filename=trim($_POST['name']);
$day=trim($_POST['day']);
$ddate=trim($_POST['ddate']);
$dmonth=trim($_POST['month']);
$dyear=trim($_POST['year']);
$time=trim($_POST['time']);
/*echo 'path '.$pathfolder.'<br/>';
echo 'filename '.$filename. '<br/>';
echo 'day' . $day.'<br/>';
echo 'time ' .$time. '<br/>';*/
if((!empty($pathfolder)) && (!empty($filename)) && (!empty($day)) && (!empty($ddate)) && (!empty($dmonth)) && (!empty($dyear)) && (!empty($time)))
{
list($hour,$minute,$second)=explode("-",$time);
echo 'hours '.$hour.'<br/>';
echo 'minutes '.$minute.'<br/>';
echo 'seconds '.$second.'<br/>';
if(($hour>=12) && ($hour<=59))
$flag="pm";
if(($hour>=00) && ($hour<=11))
$flag="am";
$filesever=$pathfolder."/".$filename.$day."-".$ddate."-".$dmonth."-".$dyear."-".$hour."-".$minute."-".$second.$flag.".html";
header("Location:$filesever") ;
}
else 'Empty Inputs';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function showFile(){
var name = document.getElementById("name").value;
var time = document.getElementById("time").value;
var dayom = document.getElementById("dayom").value;
var month = document.getElementById("month").value;
var year = document.getElementById("year").value;
var day = document.getElementById("day").value;
window.location = "address/" + name + day + "-" + dayom + "-" + month + "-" + year + "-" time + ".html";
}
</script>
<style>
input{
display:block;
}
</style>
</head>
<body>
Name: <input id="name"/>
Time: <input id="time"/>
Day of the Month <input id="dayom"/>
Month: <input id="month"/>
Year: <input id="year"/>
Day: <input id="day"/>
<button onclick="showFile()">Take me to the file</button>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.