当前位置: 编程技术>php
本页文章导读:
▪一个显示天气预报的程序
刚开始学PHP,先编写了一个程序,放在自己的主页上,可以显示天气预报,当然还很不完善,希望大家给提意见。程序如下:<?$fcont=file("http://www.bjmb.gov.cn/today.asp");$arr=array();for($i=0;$i<cou.........
▪web方式ftp
<?php/* $Id: ftp.php,v 2.2 2002/03/12 23:21:28 pauls Exp $ *//* This software came from http://inebria.com/ *//* Copyright (c) 2000 Paul Southworth. All rights reserved.Redistribution and use in source and binary forms, with or with.........
▪php中文本数据翻页(留言本翻页)
在mysq中介绍翻页的文章不少,而文本数据表格式的翻页介绍的很少,这里我就简单的说一下翻页主要介绍以下翻页思想1、留言本的翻页2、文本论坛的翻页———————————————.........
[1]一个显示天气预报的程序
来源: 互联网 发布时间: 2013-11-30
刚开始学PHP,先编写了一个程序,放在自己的主页上,可以显示天气预报,当然还很不完善,希望大家给提意见。程序如下:
<?
$fcont=file("http://www.bjmb.gov.cn/today.asp");
$arr=array();
for($i=0;$i<count($fcont);$i++){
$tmp=$fcont[$i];
$tmp=ereg_replace("<br>"," ",$tmp);
if(!strstr(strtolower($tmp),"img")){
$tmp=trim(strip_tags($tmp));
} else {
$st=ereg_replace("><",">⌒<",$tmp);
$stt=split("⌒",$st);
foreach($stt as $key => $value){
if(strstr($value,"img") ){
$tmp=$value;
$tmp=ereg_replace("src=","width=30 height=30 align=absmiddle src="/blog_article/,$tmp);_br/_ if(strstr($tmp,/index.html"bt9.jpg") || strstr($tmp,"colline.gif")) $tmp="";
}
}
}
if(trim($tmp)!="" && trim($tmp)!=" ") $arr[]=$tmp;
}
$yb=array();
for($i=2;$i<count($arr)-6;$i++){
$yb[]=$arr[$i];
}
?>
<br>
<SCRIPT LANGUAGE="JavaScript">
<!--
syb="";
<?
$exp="-3-7-9-14-18-20-25-";
for ($i=1;$i<count($yb);$i++){
if (!strstr($exp,"-".(string)($i+1)."-")){
?>
syb=syb+'<?=$yb[$i];?> ';
<?}}?>
document.write("<?=$yb[0]?>"+":");
document.write("<marquee width=400 align=middle scrollamount=5 scrolldelay=200>"+syb+"预报</marquee>");
//-->
</SCRIPT>
本来获取的语句只需要执行一次,然后将获取的数据和旧数据比较,是否是新的,如果是新的,替换掉旧数据,否则,不替换。这是有规律可寻的,先判断时间,一般比预报时间晚一个小时的话,肯定可以获取最新的预报数据了。不过现在我没有考虑那么多,以后再说吧!
<?
$fcont=file("http://www.bjmb.gov.cn/today.asp");
$arr=array();
for($i=0;$i<count($fcont);$i++){
$tmp=$fcont[$i];
$tmp=ereg_replace("<br>"," ",$tmp);
if(!strstr(strtolower($tmp),"img")){
$tmp=trim(strip_tags($tmp));
} else {
$st=ereg_replace("><",">⌒<",$tmp);
$stt=split("⌒",$st);
foreach($stt as $key => $value){
if(strstr($value,"img") ){
$tmp=$value;
$tmp=ereg_replace("src=","width=30 height=30 align=absmiddle src="/blog_article/,$tmp);_br/_ if(strstr($tmp,/index.html"bt9.jpg") || strstr($tmp,"colline.gif")) $tmp="";
}
}
}
if(trim($tmp)!="" && trim($tmp)!=" ") $arr[]=$tmp;
}
$yb=array();
for($i=2;$i<count($arr)-6;$i++){
$yb[]=$arr[$i];
}
?>
<br>
<SCRIPT LANGUAGE="JavaScript">
<!--
syb="";
<?
$exp="-3-7-9-14-18-20-25-";
for ($i=1;$i<count($yb);$i++){
if (!strstr($exp,"-".(string)($i+1)."-")){
?>
syb=syb+'<?=$yb[$i];?> ';
<?}}?>
document.write("<?=$yb[0]?>"+":");
document.write("<marquee width=400 align=middle scrollamount=5 scrolldelay=200>"+syb+"预报</marquee>");
//-->
</SCRIPT>
本来获取的语句只需要执行一次,然后将获取的数据和旧数据比较,是否是新的,如果是新的,替换掉旧数据,否则,不替换。这是有规律可寻的,先判断时间,一般比预报时间晚一个小时的话,肯定可以获取最新的预报数据了。不过现在我没有考虑那么多,以后再说吧!
[2]web方式ftp
来源: 互联网 发布时间: 2013-11-30
<?php
/* $Id: ftp.php,v 2.2 2002/03/12 23:21:28 pauls Exp $ */
/* This software came from http://inebria.com/ */
/* Copyright (c) 2000
Paul Southworth. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* Configuration Options */
$phpftp_host="localhost";
$phpftp_version="2.2";
/* Comment this out if you don't want the version footer */
$show_version_footer=1;
/* How large a file will you accept? You may also need to edit your
php.ini file and change upload_max_filesize appropriately */
$max_file_size="1000000";
/* The temporary directory $phpftp_tmpdir must exist and be writable
by your web server.
Hint: mkdir /var/tmp/xfers && chmod 1777 /var/tmp/xfers */
$phpftp_tmpdir="/var/tmp/xfers";
/* $use_mime_lookup
Turning this on creates a dependency upon the
http://www.inebria.com/mime_lookup/ MIME type lookup library.
Setting this variable to "1" enables it. "0" disables.
If you turn it on, put the mime_lookup.php file in the same directory
as ftp.php and uncomment the 'include("mime_lookup.php");' statement. */
$use_mime_lookup="0";
/* include("mime_lookup.php"); */
/* We enclose the top and bottom in functions because sometimes
we might not send them (ie, in a file-download situation) */
function phpftp_top() {
global $phpftp_version;
?>
<!-- function phpftp_top -->
<html>
<head>
<title>PHP FTP Client <?php echo $phpftp_version; ?></title>
</head>
<body bgcolor="#ffffff">
<?php
}
function phpftp_bottom() {
global $phpftp_version;
global $show_version_footer;
?>
<!-- function phpftp_bottom -->
<?php
if (isset($show_version_footer)) {
?>
<p><font size=-2>This is <a href="http://inebria.com/phpftp/">PHP FTP</a>
version <?php echo $phpftp_version; ?></font></p>
<?php
}
?>
</body>
</html>
<?php
}
/* This is the form used for initially collecting username/passwd */
function phpftp_login() {
phpftp_top();
?>
<!-- function phpftp_login -->
<p>
<form action="/blog_article/ftp.html" method=post>
<p><table border=0>
<tr><td>
Login:
</td><td>
<input name="phpftp_user" type="text">
</td></tr>
<tr><td>
Password:
</td><td>
<input name="phpftp_passwd" type="password">
</td></tr>
<tr><td>
Directory:
</td><td>
<input name="phpftp_dir" type="text">
</td></tr>
</table>
</p><p>
<input type="hidden" name="function" value="dir">
<input type="submit" value="connect">
</p>
</form>
<p>
<?php
phpftp_bottom();
}
/* This function does not return TRUE/FALSE - it returns the value of
$ftp, the current FTP stream. */
function phpftp_connect($phpftp_user,$phpftp_passwd) {
global $phpftp_host;
$ftp = ftp_connect($phpftp_host);
if ($ftp) {
if (ftp_login($ftp,$phpftp_user,urldecode($phpftp_passwd))) {
return $ftp;
}
}
}
function phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir) {
global $phpftp_host;
phpftp_top();
?>
<!-- function phpftp_list -->
<?php
$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
if (!$ftp) {
?>
<strong>FTP login failed!</strong>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
if (!$phpftp_dir) {
$phpftp_dir=ftp_pwd($ftp);
}
if (!@ftp_chdir($ftp,$phpftp_dir)) {
?>
<font color="#ff0000"><strong>Can't enter that directory!</strong></font><p><p>
<?php
$phpftp_dir=ftp_pwd($ftp);
}
echo "<strong>Current host:</strong> " . $phpftp_host . "<br>\n";
echo "<strong>Current directory:</strong> " . $phpftp_dir . "<br>\n";
if ($phpftp_dir == "/") {
$phpftp_dir="";
}
if ($contents = ftp_rawlist($ftp,"")) {
$d_i=0;
$f_i=0;
$l_i=0;
$i=0;
while ($contents[$i]) {
$item[] = split("[ ]+",$contents[$i],9);
$item_type=substr($item[$i][0],0,1);
if ($item_type == "d") {
/* it's a directory */
$nlist_dirs[$d_i]=$item[$i][8];
$d_i++;
} elseif ($item_type == "l") {
/* it's a symlink */
$nlist_links[$l_i]=$item[$i][8];
$l_i++;
} elseif ($item_type == "-") {
/* it's a file */
$nlist_files[$f_i]=$item[$i][8];
$nlist_filesize[$f_i]=$item[$i][4];
$f_i++;
} elseif ($item_type == "+") {
/* it's something on an anonftp server */
$eplf=split(",",implode(" ",$item[$i]),5);
if ($eplf[2] == "r") {
/* it's a file */
$nlist_files[$f_i]=trim($eplf[4]);
$nlist_filesize[$f_i]=substr($eplf[3],1);
$f_i++;
} elseif ($eplf[2] == "/") {
/* it's a directory */
$nlist_dirs[$d_i]=trim($eplf[3]);
$d_i++;
}
} /* ignore all others */
$i++;
}
?>
<table border=0 cellspacing=20>
<?php
if (count($nlist_dirs)>0) {
?>
<tr><td align=left valign=top>
<strong>Directories</strong><br>
<form action="/blog_article/ftp.html" method=post>
<input type="hidden" name="function" value="cd">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>">
<select name="select_directory" size="10" width="100">
<?php
for ($i=0; $i < count($nlist_dirs); $i++) {
echo "<option value=\"" . $nlist_dirs[$i] . "\">" . $nlist_dirs[$i] . "</option>\n";
}
?>
</select><br>
<input type="submit" value="Enter Directory">
</form>
</td>
<?php
}
if (count($nlist_files)>0) {
?>
<td align=left valign=top>
<strong>Files</strong><br>
<form action="/blog_article/ftp.html" method=post>
<input type="hidden" name="function" value="get">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>">
<select name="select_file" size="10">
<?php
for ($i=0; $i < count($nlist_files); $i++) {
echo "<option value=\"" . $nlist_files[$i] . "\">" . $nlist_files[$i] ." ($nlist_filesize[$i] bytes)". "</option>\n";
}
?>
</select><br>
<input type="submit" value="Download File">
</form>
</td></tr>
<?php
}
} else {
?>
<p><font color="#ff0000"><strong>Directory empty or not readable</strong></font><p>
<?php
}
?>
</table>
<p>
<form action="/blog_article/ftp.html" method=post>
<?php
$cdup=dirname($phpftp_dir);
if ($cdup == "") {
$cdup="/";
}
?>
<input type="hidden" name="function" value="dir">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $cdup; ?>">
<input type="submit" value="Go up one directory">
</form>
<p>
<form enctype="multipart/form-data" action="/blog_article/ftp.html" method=post>
<input type="hidden" name="max_file_size" value="<?php echo $max_file_size ?>">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>">
<input type="hidden" name="function" value="put">
<input type="submit" value="Upload this:">
<input name="userfile" type="file">
</form>
<p>
<form action="/blog_article/ftp.html" method=post>
<input type="hidden" name="function" value="mkdir">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>">
<input type="submit" value="Make subdirectory:">
<input name="new_dir" type="text">
<?php
ftp_quit($ftp);
phpftp_bottom();
}
}
function phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory) {
?>
<!-- function phpftp_cd -->
<?php
$new_directory=$phpftp_dir . "/" . $select_directory;
phpftp_list($phpftp_user,$phpftp_passwd,$new_directory);
}
function phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir) {
?>
<!-- function phpftp_mkdir -->
<?php
$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
if ($phpftp_dir == "") {
$phpftp_dir="/";
}
if (!$ftp) {
@ftp_quit($ftp);
phpftp_top();
?>
<font color="#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
$dir_path = $phpftp_dir . "/" . $new_dir;
@ftp_mkdir($ftp,$dir_path);
@ftp_quit($ftp);
phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
}
};
function phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file) {
$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
if ($phpftp_dir == "") {
$phpftp_dir="/";
}
if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) {
@ftp_quit($ftp);
phpftp_top();
?>
<font color="#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
srand((double)microtime()*1000000);
$randval = rand();
$tmpfile=$phpftp_tmpdir . "/" . $select_file . "." . $randval;
if (!ftp_get($ftp,$tmpfile,$select_file,FTP_BINARY)) {
ftp_quit($ftp);
phpftp_top();
?>
<font color="#ff0000"><strong>FTP get failed!</strong></font><p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
ftp_quit($ftp);
global $use_mime_lookup;
if ($use_mime_lookup == "1") {
$file_mime_type=mime_lookup(substr(strrchr($select_file,"."),1));
}
if (!$file_mime_type) {
$file_mime_type="application/octet-stream";
}
header("Content-Type: " . $file_mime_type);
header("Content-Disposition: attachment; filename=" . $select_file);
readfile($tmpfile);
}
@unlink($tmpfile);
}
}
function phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name) {
srand((double)microtime()*1000000);
$randval = rand();
$tmpfile=$phpftp_tmpdir . "/" . $userfile_name . "." . $randval;
if (!@move_uploaded_file($userfile,$tmpfile)) {
phpftp_top();
?>
<font color="#ff0000"><strong>Upload failed! Can't create temp file?</strong></font>
<p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
if (!$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd)) {
unlink($tmpfile);
phpftp_top();
?>
<font color="#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
ftp_chdir($ftp,$phpftp_dir);
ftp_put($ftp,$userfile_name,$tmpfile,FTP_BINARY);
ftp_quit($ftp);
unlink($tmpfile);
phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
}
}
}
switch($function) {
case "dir";
phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
break;
case "cd";
phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory);
break;
case "get";
phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file);
break;
case "put";
phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name);
break;
case "mkdir";
phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir);
break;
case "";
phpftp_login();
break;
}
?>
/* $Id: ftp.php,v 2.2 2002/03/12 23:21:28 pauls Exp $ */
/* This software came from http://inebria.com/ */
/* Copyright (c) 2000
Paul Southworth. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* Configuration Options */
$phpftp_host="localhost";
$phpftp_version="2.2";
/* Comment this out if you don't want the version footer */
$show_version_footer=1;
/* How large a file will you accept? You may also need to edit your
php.ini file and change upload_max_filesize appropriately */
$max_file_size="1000000";
/* The temporary directory $phpftp_tmpdir must exist and be writable
by your web server.
Hint: mkdir /var/tmp/xfers && chmod 1777 /var/tmp/xfers */
$phpftp_tmpdir="/var/tmp/xfers";
/* $use_mime_lookup
Turning this on creates a dependency upon the
http://www.inebria.com/mime_lookup/ MIME type lookup library.
Setting this variable to "1" enables it. "0" disables.
If you turn it on, put the mime_lookup.php file in the same directory
as ftp.php and uncomment the 'include("mime_lookup.php");' statement. */
$use_mime_lookup="0";
/* include("mime_lookup.php"); */
/* We enclose the top and bottom in functions because sometimes
we might not send them (ie, in a file-download situation) */
function phpftp_top() {
global $phpftp_version;
?>
<!-- function phpftp_top -->
<html>
<head>
<title>PHP FTP Client <?php echo $phpftp_version; ?></title>
</head>
<body bgcolor="#ffffff">
<?php
}
function phpftp_bottom() {
global $phpftp_version;
global $show_version_footer;
?>
<!-- function phpftp_bottom -->
<?php
if (isset($show_version_footer)) {
?>
<p><font size=-2>This is <a href="http://inebria.com/phpftp/">PHP FTP</a>
version <?php echo $phpftp_version; ?></font></p>
<?php
}
?>
</body>
</html>
<?php
}
/* This is the form used for initially collecting username/passwd */
function phpftp_login() {
phpftp_top();
?>
<!-- function phpftp_login -->
<p>
<form action="/blog_article/ftp.html" method=post>
<p><table border=0>
<tr><td>
Login:
</td><td>
<input name="phpftp_user" type="text">
</td></tr>
<tr><td>
Password:
</td><td>
<input name="phpftp_passwd" type="password">
</td></tr>
<tr><td>
Directory:
</td><td>
<input name="phpftp_dir" type="text">
</td></tr>
</table>
</p><p>
<input type="hidden" name="function" value="dir">
<input type="submit" value="connect">
</p>
</form>
<p>
<?php
phpftp_bottom();
}
/* This function does not return TRUE/FALSE - it returns the value of
$ftp, the current FTP stream. */
function phpftp_connect($phpftp_user,$phpftp_passwd) {
global $phpftp_host;
$ftp = ftp_connect($phpftp_host);
if ($ftp) {
if (ftp_login($ftp,$phpftp_user,urldecode($phpftp_passwd))) {
return $ftp;
}
}
}
function phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir) {
global $phpftp_host;
phpftp_top();
?>
<!-- function phpftp_list -->
<?php
$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
if (!$ftp) {
?>
<strong>FTP login failed!</strong>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
if (!$phpftp_dir) {
$phpftp_dir=ftp_pwd($ftp);
}
if (!@ftp_chdir($ftp,$phpftp_dir)) {
?>
<font color="#ff0000"><strong>Can't enter that directory!</strong></font><p><p>
<?php
$phpftp_dir=ftp_pwd($ftp);
}
echo "<strong>Current host:</strong> " . $phpftp_host . "<br>\n";
echo "<strong>Current directory:</strong> " . $phpftp_dir . "<br>\n";
if ($phpftp_dir == "/") {
$phpftp_dir="";
}
if ($contents = ftp_rawlist($ftp,"")) {
$d_i=0;
$f_i=0;
$l_i=0;
$i=0;
while ($contents[$i]) {
$item[] = split("[ ]+",$contents[$i],9);
$item_type=substr($item[$i][0],0,1);
if ($item_type == "d") {
/* it's a directory */
$nlist_dirs[$d_i]=$item[$i][8];
$d_i++;
} elseif ($item_type == "l") {
/* it's a symlink */
$nlist_links[$l_i]=$item[$i][8];
$l_i++;
} elseif ($item_type == "-") {
/* it's a file */
$nlist_files[$f_i]=$item[$i][8];
$nlist_filesize[$f_i]=$item[$i][4];
$f_i++;
} elseif ($item_type == "+") {
/* it's something on an anonftp server */
$eplf=split(",",implode(" ",$item[$i]),5);
if ($eplf[2] == "r") {
/* it's a file */
$nlist_files[$f_i]=trim($eplf[4]);
$nlist_filesize[$f_i]=substr($eplf[3],1);
$f_i++;
} elseif ($eplf[2] == "/") {
/* it's a directory */
$nlist_dirs[$d_i]=trim($eplf[3]);
$d_i++;
}
} /* ignore all others */
$i++;
}
?>
<table border=0 cellspacing=20>
<?php
if (count($nlist_dirs)>0) {
?>
<tr><td align=left valign=top>
<strong>Directories</strong><br>
<form action="/blog_article/ftp.html" method=post>
<input type="hidden" name="function" value="cd">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>">
<select name="select_directory" size="10" width="100">
<?php
for ($i=0; $i < count($nlist_dirs); $i++) {
echo "<option value=\"" . $nlist_dirs[$i] . "\">" . $nlist_dirs[$i] . "</option>\n";
}
?>
</select><br>
<input type="submit" value="Enter Directory">
</form>
</td>
<?php
}
if (count($nlist_files)>0) {
?>
<td align=left valign=top>
<strong>Files</strong><br>
<form action="/blog_article/ftp.html" method=post>
<input type="hidden" name="function" value="get">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>">
<select name="select_file" size="10">
<?php
for ($i=0; $i < count($nlist_files); $i++) {
echo "<option value=\"" . $nlist_files[$i] . "\">" . $nlist_files[$i] ." ($nlist_filesize[$i] bytes)". "</option>\n";
}
?>
</select><br>
<input type="submit" value="Download File">
</form>
</td></tr>
<?php
}
} else {
?>
<p><font color="#ff0000"><strong>Directory empty or not readable</strong></font><p>
<?php
}
?>
</table>
<p>
<form action="/blog_article/ftp.html" method=post>
<?php
$cdup=dirname($phpftp_dir);
if ($cdup == "") {
$cdup="/";
}
?>
<input type="hidden" name="function" value="dir">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $cdup; ?>">
<input type="submit" value="Go up one directory">
</form>
<p>
<form enctype="multipart/form-data" action="/blog_article/ftp.html" method=post>
<input type="hidden" name="max_file_size" value="<?php echo $max_file_size ?>">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>">
<input type="hidden" name="function" value="put">
<input type="submit" value="Upload this:">
<input name="userfile" type="file">
</form>
<p>
<form action="/blog_article/ftp.html" method=post>
<input type="hidden" name="function" value="mkdir">
<input type="hidden" name="phpftp_user" value="<?php echo $phpftp_user; ?>">
<input type="hidden" name="phpftp_passwd" value="<?php echo $phpftp_passwd; ?>">
<input type="hidden" name="phpftp_dir" value="<?php echo $phpftp_dir; ?>">
<input type="submit" value="Make subdirectory:">
<input name="new_dir" type="text">
<?php
ftp_quit($ftp);
phpftp_bottom();
}
}
function phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory) {
?>
<!-- function phpftp_cd -->
<?php
$new_directory=$phpftp_dir . "/" . $select_directory;
phpftp_list($phpftp_user,$phpftp_passwd,$new_directory);
}
function phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir) {
?>
<!-- function phpftp_mkdir -->
<?php
$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
if ($phpftp_dir == "") {
$phpftp_dir="/";
}
if (!$ftp) {
@ftp_quit($ftp);
phpftp_top();
?>
<font color="#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
$dir_path = $phpftp_dir . "/" . $new_dir;
@ftp_mkdir($ftp,$dir_path);
@ftp_quit($ftp);
phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
}
};
function phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file) {
$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
if ($phpftp_dir == "") {
$phpftp_dir="/";
}
if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) {
@ftp_quit($ftp);
phpftp_top();
?>
<font color="#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
srand((double)microtime()*1000000);
$randval = rand();
$tmpfile=$phpftp_tmpdir . "/" . $select_file . "." . $randval;
if (!ftp_get($ftp,$tmpfile,$select_file,FTP_BINARY)) {
ftp_quit($ftp);
phpftp_top();
?>
<font color="#ff0000"><strong>FTP get failed!</strong></font><p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
ftp_quit($ftp);
global $use_mime_lookup;
if ($use_mime_lookup == "1") {
$file_mime_type=mime_lookup(substr(strrchr($select_file,"."),1));
}
if (!$file_mime_type) {
$file_mime_type="application/octet-stream";
}
header("Content-Type: " . $file_mime_type);
header("Content-Disposition: attachment; filename=" . $select_file);
readfile($tmpfile);
}
@unlink($tmpfile);
}
}
function phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name) {
srand((double)microtime()*1000000);
$randval = rand();
$tmpfile=$phpftp_tmpdir . "/" . $userfile_name . "." . $randval;
if (!@move_uploaded_file($userfile,$tmpfile)) {
phpftp_top();
?>
<font color="#ff0000"><strong>Upload failed! Can't create temp file?</strong></font>
<p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
if (!$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd)) {
unlink($tmpfile);
phpftp_top();
?>
<font color="#ff0000"><strong>FTP login failed!</strong></font><p><p>
<a href="/blog_article/ftp.html">Start over?</a>
<?php
phpftp_bottom();
} else {
ftp_chdir($ftp,$phpftp_dir);
ftp_put($ftp,$userfile_name,$tmpfile,FTP_BINARY);
ftp_quit($ftp);
unlink($tmpfile);
phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
}
}
}
switch($function) {
case "dir";
phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
break;
case "cd";
phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory);
break;
case "get";
phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file);
break;
case "put";
phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name);
break;
case "mkdir";
phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir);
break;
case "";
phpftp_login();
break;
}
?>
[3]php中文本数据翻页(留言本翻页)
来源: 互联网 发布时间: 2013-11-30
在mysq中介绍翻页的文章不少,而文本数据表格式的翻页介绍的很少,这里我就简单的说一下翻页
主要介绍以下翻页思想
1、留言本的翻页
2、文本论坛的翻页
————————————————————————
留言本的翻页:
——————————————————————————————
这个在文本数据表中的翻页是最简单的翻页,这样说明一下
golbal file
Data.dat --- NOTE FILE USE
user.dat --- Forum File use
Data.dat
_______________________________________________________________________
[1] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[2] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[3] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[4] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[5] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
说明:
其中的[1,2,3,4,5....]是我自己添加进去的,主要是为了大家更好的理解
index.php source:.
__________________________________________________
---====BOF====---
<?
$file = "data.dat"; //数据文件
if(file_exits($file)){ //容错处理,防止无数据文件存在
$fp=fopen($file,"w+");
fclose($fp);
unset($fp);
}
$listnumber = 20; //每页显示条数
$fp = file($file); //读取数据到内容中
$number = count($fp); //计算总数据量
$pagenumber = floor($number/$listnumber)+1;
if($number<1){
print "暂时无记录,欢迎留言";
/*+--------------------------------+
|在这里打印FORM表单或连接到表但的|
| URL, |
+--------------------------------+*/
}else{
if(empty($_POST["page"])){ //这段IF...ELSE...是为了兼容php4.20的默认设置,防止出现无效的全局变量而写的
$page = 0; //因为是从数据文本读出来的,保存在数组中,有个O下标
}else{
$page = $_POST["page"]
}
if($page<0 || $page>pagenumber){ //检错处理,当页面参数跳出总页面或小于首页(0)的时候,将返回到第一页
$page=0;
}
$startnote = $page*$listnumber; //开始记录位置
$endnote = $startnote+$listnumber; //结束记录位置
//for($int_a=$startnote;$int_a<$endnote;$int_a++){ //排序显示类似ASC模式
pirnt "<table>"
for($int_a=$endnote;$int_a>=$startnote;$int_a--){ //排序显示类似DESC模式
$info=explode("\t",$fp[$int-a]); //切割数据获得每条记录的详细数据我这里是用了一个TAB键分割
print "<tr><td>用户:$info[1] 标题$info[2] 发言内容:$info[3] 发布时间:$info[4] IP:$info[5]";
}
$prevpage = $page-1; //上一页的PAGE数
$nextpage = $page+1; //下一页的page数
print "<tr><td>
<a href=/index.html"$_SERVER["PHP_SELF"]?page=0\">首页</a>
<a href=/index.html"$_SERVER["PHP_SELF"]?page=$prevpage\">上一页</a>
<a href=/index.html"$_SERVER["PHP_SELF"]?page=$nextpage\">下一页</a>
<a href=/index.html"$_SERVER["PHP_SELF"]?page=$pagenumber\">尾页</a>
</table>"; //这里您可以直接将页面的检测加到这里,那样给别人看的是舒服的,但是效果是一样的
//例如:这里有可能出现20页出现 <a href="/blog_article/index/page/21.html">下一页</a> 或<a href="/blog_article/index/page/-1.html">
}
?>
---====EOF====---
写的仓促,另外中间有不少因为考虑到使用PHP4.20所以就改变了一下,比如说PHP_SELF已经采用_SERVER["PHP_SELF"]等
主要介绍以下翻页思想
1、留言本的翻页
2、文本论坛的翻页
————————————————————————
留言本的翻页:
——————————————————————————————
这个在文本数据表中的翻页是最简单的翻页,这样说明一下
golbal file
Data.dat --- NOTE FILE USE
user.dat --- Forum File use
Data.dat
_______________________________________________________________________
[1] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[2] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[3] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[4] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
[5] [POSTUSER] [TITLE] [MEM] [POSTTIME] [IP]
说明:
其中的[1,2,3,4,5....]是我自己添加进去的,主要是为了大家更好的理解
index.php source:.
__________________________________________________
---====BOF====---
<?
$file = "data.dat"; //数据文件
if(file_exits($file)){ //容错处理,防止无数据文件存在
$fp=fopen($file,"w+");
fclose($fp);
unset($fp);
}
$listnumber = 20; //每页显示条数
$fp = file($file); //读取数据到内容中
$number = count($fp); //计算总数据量
$pagenumber = floor($number/$listnumber)+1;
if($number<1){
print "暂时无记录,欢迎留言";
/*+--------------------------------+
|在这里打印FORM表单或连接到表但的|
| URL, |
+--------------------------------+*/
}else{
if(empty($_POST["page"])){ //这段IF...ELSE...是为了兼容php4.20的默认设置,防止出现无效的全局变量而写的
$page = 0; //因为是从数据文本读出来的,保存在数组中,有个O下标
}else{
$page = $_POST["page"]
}
if($page<0 || $page>pagenumber){ //检错处理,当页面参数跳出总页面或小于首页(0)的时候,将返回到第一页
$page=0;
}
$startnote = $page*$listnumber; //开始记录位置
$endnote = $startnote+$listnumber; //结束记录位置
//for($int_a=$startnote;$int_a<$endnote;$int_a++){ //排序显示类似ASC模式
pirnt "<table>"
for($int_a=$endnote;$int_a>=$startnote;$int_a--){ //排序显示类似DESC模式
$info=explode("\t",$fp[$int-a]); //切割数据获得每条记录的详细数据我这里是用了一个TAB键分割
print "<tr><td>用户:$info[1] 标题$info[2] 发言内容:$info[3] 发布时间:$info[4] IP:$info[5]";
}
$prevpage = $page-1; //上一页的PAGE数
$nextpage = $page+1; //下一页的page数
print "<tr><td>
<a href=/index.html"$_SERVER["PHP_SELF"]?page=0\">首页</a>
<a href=/index.html"$_SERVER["PHP_SELF"]?page=$prevpage\">上一页</a>
<a href=/index.html"$_SERVER["PHP_SELF"]?page=$nextpage\">下一页</a>
<a href=/index.html"$_SERVER["PHP_SELF"]?page=$pagenumber\">尾页</a>
</table>"; //这里您可以直接将页面的检测加到这里,那样给别人看的是舒服的,但是效果是一样的
//例如:这里有可能出现20页出现 <a href="/blog_article/index/page/21.html">下一页</a> 或<a href="/blog_article/index/page/-1.html">
}
?>
---====EOF====---
写的仓促,另外中间有不少因为考虑到使用PHP4.20所以就改变了一下,比如说PHP_SELF已经采用_SERVER["PHP_SELF"]等
最新技术文章: