php本身是不具备可以带有实时上传进度条功能了,如果想有这种功能我们一般会使用ajax来实现,但是php提供了一个apc,他就可以与php配置实现上传进度条哦。
主要针对的是window上的应用。
1.服务器要支持apc扩展,没有此扩展的话,百度一下php_apc.dll ,下载一个扩展扩展要求php.5.2以上。
2.配置apc相关配置,重启apache
代码如下 |
复制代码 |
extension=php_apc.dll
apc.rfc1867 = on
apc.max_file_size = 1000M
upload_max_filesize = 1000M
post_max_size = 1000M
|
说明一下:至于参数要配多大,得看项目需要apc.max_file_size, 设置apc所支持上传文件的大小,要求apc.max_file_size <=upload_max_filesize 并且apc.max_file_size <=post_max_size.重新启动apache即可实现apc的支持.
3.在代码里面利用phpinfo();查看apc扩展安装了没有。
4.下面是实现代码:
getprogress.php
代码如下 |
复制代码 |
<?php
session_start();
if(isset($_GET['progress_key'])) {
$status = apc_fetch('upload_'.$_GET['progress_key']);
echo ($status['current']/$status['total'])*100;
}
?>
upload.php
PHP Code
<?php
$id = $_GET['id'];
?>
<form enctype="multipart/form-data" id="upload_form" action="target.php" method="POST">
<input type="hidden" name="APC_UPLOAD_PROGRESS"
id="progress_key" value="<?php echo $id?>"/>
<input type="file" id="test_file" name="test_file"/><br/>
<input onclick="window.parent.startProgress(); return true;"
type="submit" value="上传"/>
</form>
|
target.php
代码如下 |
复制代码 |
<?php
set_time_limit(600);
if($_SERVER['REQUEST_METHOD']=='POST') {
move_uploaded_file($_FILES["test_file"]["tmp_name"],
dirname($_SERVER['SCRIPT_FILENAME'])."/UploadTemp/" . $_FILES["test_file"]["name"]);//UploadTemp文件夹位于此脚本相同目录下
echo "<p>上传成功</p>";
}
?>
|
index.php
代码如下 |
复制代码 |
<?php
$id = md5(uniqid(rand(), true));
?>
<html>
<head><title>上传进度</title></head>
<body>
<script" width=100% src="js/jquery-1.4.4.min.js" language="javascript"></script>
<script language="javascript">
var proNum=0;
var loop=0;
var progressResult;
function sendURL() {
$.ajax({
type : 'GET',
url : "getprogress.php?progress_key=<?php echo $id;?>",
async : true,
cache : false,
dataType : 'json',
data: "progress_key=<?php echo $id;?>",
success : function(e) {
progressResult = e;
proNum=parseInt(progressResult);
document.getElementById("progressinner").style.width = proNum+"%";
document.getElementById("showNum").innerHTML = proNum+"%";
if ( proNum < 100){
setTimeout("getProgress()", 100);
}
}
});
}
function getProgress(){
loop++;
sendURL();
}
var interval;
function startProgress(){
document.getElementById("progressouter").style.display="block";
setTimeout("getProgress()", 100);
}
</script>
<iframe id="theframe" name="theframe"
" width=100% src="upload.php?id=<?php echo $id; ?>"
style="border: none; height: 100px; width: 400px;" >
</iframe>
<br/><br/>
<div id="progressouter" style="width: 500px; height: 20px; border: 6px solid red; display:none;">
<div id="progressinner" style="position: relative; height: 20px; background-color: purple; width: 0%; "></div>
</div>
<div id='showNum'></div><br>
<div id='showNum2'></div>
</body>
</html>
|
PHPExcel类是php一个excel表格处理插件了,下面我来给大家介绍利用PHPExcel类来导入与导出excel表格的应用方法,有需要了解的朋友不防参考参考(PHPExcel自己百度下载这里不介绍了)。
导出Excel用法
//设置环境变量(新增PHPExcel)
代码如下 |
复制代码 |
set_include_path('.'. PATH_SEPARATOR . Yii::app()->basePath.'/lib/PHPExcel' . PATH_SEPARATOR .
get_include_path());
//注:在yii中,也可以直接Yii::import(“application.lib.PHPExcel.*”);
//引入PHPExcel相关文件
require_once "PHPExcel.php";
require_once 'PHPExcel/IOFactory.php';
require_once 'PHPExcel/Writer/Excel5.php';
|
//把要导出的内容放到表格
代码如下 |
复制代码 |
//新建
$resultPHPExcel = new PHPExcel();
//设置参数
//设值
$resultPHPExcel->getActiveSheet()->setCellValue('A1', '季度');
$resultPHPExcel->getActiveSheet()->setCellValue('B1', '名称');
$resultPHPExcel->getActiveSheet()->setCellValue('C1', '数量');
$i = 2;
foreach($data as $item){
$resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $item['quarter']);
$resultPHPExcel->getActiveSheet()->setCellValue('B' . $i, $item['name']);
$resultPHPExcel->getActiveSheet()->setCellValue('C' . $i, $item['number']);
$i ++;
}
|
设置导出参数
代码如下 |
复制代码 |
//设置导出文件名
$outputFileName = 'total.xls';
$xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel);
//ob_start(); ob_flush();
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$outputFileName.'"');
header("Content-Transfer-Encoding: binary");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$xlsWriter->save( "php://output" );
|
输出有错。
默认$xlsWriter->save( "php://output" );可能因为缓存不够大,而显示不完整,所以做个中转,方式如下:
代码如下 |
复制代码 |
$finalFileName = (Yii::app()->basePath.'/runtime/'.time().'.xls';
$xlsWriter->save($finalFileName);
echo file_get_contents($finalFileName);
|
//file_get_contents() 函数把整个文件读入一个字符串中。和 file() 一样,不同的是 file_get_contents() 把文
件读入一个字符串。
导入Excel用法
代码如下 |
复制代码 |
<?
if($_POST['leadExcel'] == "true")
{
$filename = $_FILES['inputExcel']['name'];
$tmp_name = $_FILES['inputExcel']['tmp_name'];
$msg = uploadFile($filename,$tmp_name);
echo $msg;
}
//导入Excel文件
function uploadFile($file,$filetempname)
{
//自己设置的上传文件存放路径
$filePath = 'upFile/';
$str = "";
//下面的路径按照你PHPExcel的路径来修改
require_once '../PHPExcel/PHPExcel.php';
require_once '../PHPExcel/PHPExcel/IOFactory.php';
require_once '../PHPExcel/PHPExcel/Reader/Excel5.php';
//注意设置时区
$time=date("y-m-d-H-i-s");//去当前上传的时间
//获取上传文件的扩展名
$extend=strrchr ($file,'.');
//上传后的文件名
$name=$time.$extend;
$uploadfile=$filePath.$name;//上传后的文件名地址
//move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
$result=move_uploaded_file($filetempname,$uploadfile);//假如上传到当前目录下
//echo $result;
if($result) //如果上传文件成功,就执行导入excel操作
{
include "conn.php";
$objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
$objPHPExcel = $objReader->load($uploadfile);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); //取得总行数
$highestColumn = $sheet->getHighestColumn(); //取得总列数
/* 第一种方法
//循环读取excel文件,读取一条,插入一条
for($j=1;$j<=$highestRow;$j++) //从第一行开始读取数据
{
for($k='A';$k<=$highestColumn;$k++) //从A列读取数据
{
//
这种方法简单,但有不妥,以'\'合并为数组,再分割\为字段值插入到数据库
实测在excel中,如果某单元格的值包含了\导入的数据会为空
//
$str .=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue().'\';//读取单元格
}
//echo $str; die();
//explode:函数把字符串分割为数组。
$strs = explode("\",$str);
$sql = "INSERT INTO te(`1`, `2`, `3`, `4`, `5`) VALUES (
'{$strs[0]}',
'{$strs[1]}',
'{$strs[2]}',
'{$strs[3]}',
'{$strs[4]}')";
//die($sql);
if(!mysql_query($sql))
{
return false;
echo 'sql语句有误';
}
$str = "";
}
unlink($uploadfile); //删除上传的excel文件
$msg = "导入成功!";
*/
/* 第二种方法*/
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow();
echo 'highestRow='.$highestRow;
echo "<br>";
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
echo 'highestColumnIndex='.$highestColumnIndex;
echo "<br>";
$headtitle=array();
for ($row = 1;$row <= $highestRow;$row++)
{
$strs=array();
//注意highestColumnIndex的列数索引从0开始
for ($col = 0;$col < $highestColumnIndex;$col++)
{
$strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
}
$sql = "INSERT INTO te(`1`, `2`, `3`, `4`, `5`) VALUES (
'{$strs[0]}',
'{$strs[1]}',
'{$strs[2]}',
'{$strs[3]}',
'{$strs[4]}')";
//die($sql);
if(!mysql_query($sql))
{
return false;
echo 'sql语句有误';
}
}
}
else
{
$msg = "导入失败!";
}
return $msg;
}
?>
|
HTML网页代码
代码如下 |
复制代码 |
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="leadExcel" value="true">
<table align="center" width="90%" border="0">
<tr>
<td>
<input type="file" name="inputExcel"><input type="submit" value="导入数据">
</td>
</tr>
</table>
</form>
|
小偷程序其实就是利用了php中的一特定函数实现采集别人网站的内容,然后通过正则分析把我们想要的内容保存到自己本地数据库了,下面我来介绍php小偷程序的实现方法,有需要的朋友可参考。
在下面采集数据过程中file_get_contents函数是关键了,下面我们来看看file_get_contents函数语法
string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
和 file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。如果失败, file_get_contents() 将返回 FALSE。
file_get_contents() 函数是用来将文件的内容读入到一个字符串中的首选方法。如果操作系统支持还会使用内存映射技术来增强性能。
例
代码如下 |
复制代码 |
<?php
$homepage = file_get_contents('http://www.111cn.net/');
echo $homepage;
?>
|
这样$homepage就是我们采集网的内容给保存下来了,好了说了这么多我们开始吧。
例
代码如下 |
复制代码 |
<?php
function fetch_urlpage_contents($url){
$c=file_get_contents($url);
return $c;
}
//获取匹配内容
function fetch_match_contents($begin,$end,$c)
{
$begin=change_match_string($begin);
$end=change_match_string($end);
$p = "{$begin}(.*){$end}";
if(eregi($p,$c,$rs))
{
return $rs[1];}
else { return "";}
}//转义正则表达式字符串
function change_match_string($str){
//注意,以下只是简单转义
//$old=array("/","$");
//$new=array("/","$");
$str=str_replace($old,$new,$str);
return $str;
}
//采集网页
function pick($url,$ft,$th)
{
$c=fetch_urlpage_contents($url);
foreach($ft as $key => $value)
{
$rs[$key]=fetch_match_contents($value["begin"],$value["end"],$c);
if(is_array($th[$key]))
{ foreach($th[$key] as $old => $new)
{
$rs[$key]=str_replace($old,$new,$rs[$key]);
}
}
}
return $rs;
}
$url="http://www.111cn.net"; //要采集的地址
$ft["title"]["begin"]="<title>"; //截取的开始点
$ft["title"]["end"]="</title>"; //截取的结束点
$th["title"]["中山"]="广东"; //截取部分的替换
$ft["body"]["begin"]="<body>"; //截取的开始点
$ft["body"]["end"]="</body>"; //截取的结束点
$th["body"]["中山"]="广东"; //截取部分的替换
$rs=pick($url,$ft,$th); //开始采集
echo $rs["title"];
echo $rs["body"]; //输出
?>
|
以下代码从上一面修改而来,专门用于提取网页所有超链接,邮箱或其他特定内容
代码如下 |
复制代码 |
<?php
function fetch_urlpage_contents($url){
$c=file_get_contents($url);
return $c;
}
//获取匹配内容
function fetch_match_contents($begin,$end,$c)
{
$begin=change_match_string($begin);
$end=change_match_string($end);
$p = "#{$begin}(.*){$end}#iU";//i表示忽略大小写,U禁止贪婪匹配
if(preg_match_all($p,$c,$rs))
{
return $rs;}
else { return "";}
}//转义正则表达式字符串
function change_match_string($str){
//注意,以下只是简单转义
$old=array("/","$",'?');
$new=array("/","$",'?');
$str=str_replace($old,$new,$str);
return $str;
}
//采集网页
function pick($url,$ft,$th)
{
$c=fetch_urlpage_contents($url);
foreach($ft as $key => $value)
{
$rs[$key]=fetch_match_contents($value["begin"],$value["end"],$c);
if(is_array($th[$key]))
{ foreach($th[$key] as $old => $new)
{
$rs[$key]=str_replace($old,$new,$rs[$key]);
}
}
}
return $rs;
}
$url="http://www.111cn.net"; //要采集的地址
$ft["a"]["begin"]='<a'; //截取的开始点<br />
$ft["a"]["end"]='>'; //截取的结束点
$rs=pick($url,$ft,$th); //开始采集
print_r($rs["a"]);
?>
|
小提示file_get_contents很是容易被防采集了,我们可以使用curl来模仿用户对网站进行访问,这算比上面要高级不少哦,file_get_contents()效率稍低些,常用失败的情况、curl()效率挺高的,支持多线程,不过需要开启下curl扩展。下面是curl扩展开启的步骤:
1、将PHP文件夹下的三个文件php_curl.dll,libeay32.dll,ssleay32.dll复制到system32下;
2、将php.ini(c:WINDOWS目录下)中的;extension=php_curl.dll中的分号去掉;
3、重启apache或者IIS。
简单的抓取页面函数,附带伪造 Referer 和 User_Agent 功能
代码如下 |
复制代码 |
<?php
function GetSources($Url,$User_Agent='',$Referer_Url='') //抓取某个指定的页面
{
//$Url 需要抓取的页面地址
//$User_Agent 需要返回的user_agent信息 如“baiduspider”或“googlebot”
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $Url);
curl_setopt ($ch, CURLOPT_USERAGENT, $User_Agent);
curl_setopt ($ch, CURLOPT_REFERER, $Referer_Url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$MySources = curl_exec ($ch);
curl_close($ch);
return $MySources;
}
$Url = "http://www.111cn.net"; //要获取内容的也没
$User_Agent = "baiduspider+(+http://www.baidu.com/search/spider.htm)";
$Referer_Url = 'http://www.111cn.net/';
echo GetSources($Url,$User_Agent,$Referer_Url);
?>
|
本人给大家推一个不错php文件缓存类文件,从各方面来看本缓存类很合理并且适用于大型网站使用哦,有需要的朋友可参考参考。
代码如下 |
复制代码 |
<?php
class Cache {
/** 缓存目录 **/
var $CacheDir = './c';
/** 缓存的文件 **/
var $CacheFile = '';
/** 文件缓存时间(分钟) **/
var $CacheTime = 0;
/** 文件是否已缓存 **/
var $CacheFound = False;
/** 错误及调试信息 **/
var $DebugMsg = NULL;
function Cache($CacheTime = 0) {
$this->CacheTime = $CacheTime;
}
private function Run() {
/** 缓存时间大于0,检测缓存文件的修改时间,在缓存时间内为缓存文件名,超过缓存时间为False,
小于等于0,返回false,并清理已缓存的文件
**/
Return $this->CacheTime ? $this->CheckCacheFile() : $this->CleanCacheFile();
}
function GetCache($VistUrl,$CacheFileType = 'html')
{
$this->SetCacheFile($VistUrl,$CacheFileType);
$fileName=$this->CheckCacheFile();
if($fileName)
{
$fp = fopen($fileName,"r");
$content_= fread($fp, filesize($fileName));
fclose($fp);
return $content_;
}
else
{
return false;
}
}
private function SetCacheFile($VistUrl,$CacheFileType = 'html') {
if(empty($VistUrl)) {
/** 默认为index.html **/
$this->CacheFile = 'index';
}else {
/** 传递参数为$_POST时 **/
$this->CacheFile = is_array($VistUrl) ? implode('.',$VistUrl) : $VistUrl;
}
$this->CacheFile = $this->CacheDir.'/'.md5($this->CacheFile);
$this->CacheFile.= '.'.$CacheFileType;
}
function SetCacheTime($t = 60) {
$this->CacheTime = $t;
}
private function CheckCacheFile() {
if(!$this->CacheTime || !file_exists($this->CacheFile)) {Return False;}
/** 比较文件的建立/修改日期和当前日期的时间差 **/
$GetTime=(Time()-Filemtime($this->CacheFile))/(60*1);
/** Filemtime函数有缓存,注意清理 **/
Clearstatcache();
$this->Debug('Time Limit '.($GetTime*60).'/'.($this->CacheTime*60).'');
$this->CacheFound = $GetTime <= $this->CacheTime ? $this->CacheFile : False;
Return $this->CacheFound;
}
function SaveToCacheFile($VistUrl,$Content,$CacheFileType = 'html') {
$this->SetCacheFile($VistUrl,$CacheFileType);
if(!$this->CacheTime) {
Return False;
}
/** 检测缓存目录是否存在 **/
if(true === $this->CheckCacheDir()) {
$CacheFile = $this->CacheFile;
$CacheFile = str_replace('//','/',$CacheFile);
$fp = @fopen($CacheFile,"wb");
if(!$fp) {
$this->Debug('Open File '.$CacheFile.' Fail');
}else {
if(@!fwrite($fp,$Content)){
$this->Debug('Write '.$CacheFile.' Fail');
}else {
$this->Debug('Cached File');
};
@fclose($fp);
}
}else {
/** 缓存目录不存在,或不能建立目录 **/
$this->Debug('Cache Folder '.$this->CacheDir.' Not Found');
}
}
private function CheckCacheDir() {
if(file_exists($this->CacheDir)) { Return true; }
/** 保存当前工作目录 **/
$Location = getcwd();
/** 把路径划分成单个目录 **/
$Dir = split("/", $this->CacheDir);
/** 循环建立目录 **/
$CatchErr = True;
for ($i=0; $i<count($Dir); $i++){
if (!file_exists($Dir[$i])){
/** 建立目录失败会返回False 返回建立最后一个目录的返回值 **/
$CatchErr = @mkdir($Dir[$i],0777);
}
@chdir($Dir[$i]);
}
/** 建立完成后要切换到原目录 **/
chdir($Location);
if(!$CatchErr) {
$this->Debug('Create Folder '.$this->CacheDir.' Fail');
}
Return $CatchErr;
}
private function CleanCacheFile() {
if(file_exists($this->CacheFile)) {
@chmod($this->CacheFile,777);
@unlink($this->CacheFile);
}
/** 置没有缓存文件 **/
$this->CacheFound = False;
Return $this->CacheFound;
}
function Debug($msg='') {
if(DEBUG) {
$this->DebugMsg[] = '[Cache]'.$msg;
}
}
function GetError() {
Return empty($this->DebugMsg) ? '' : "<br>n".implode("<br>n",$this->DebugMsg);
}
}/* end of class */
?>
|
在php中我们也有可以直接来操作ftp,然后利用php实现与ftp一样的文件上传与下载文件的功能哦,下面我来介绍一个完整的实例。
一、LycFtpAbstract.class.php FTP基类
代码如下 |
复制代码 |
<?php
/* author:凹凸曼(lyc)
/* email: jar-c@163.com
/* time : 2011-04-22
*/
abstract class Lyc_Ftp_Abstract {
protected $ftpobj=null;
protected $host='';
protected $user='anonymous';
protected $pwd='';
protected $mode=FTP_BINARY;
protected $port=21;
protected $timeout=90;
protected $pasv=TRUE;
protected function init(){
}
/**
* 建立ftp连接
*
*/
protected function connect(){
$this->ftpobj=@ftp_connect($this->host,$this->port,$this->timeout);
if(null==$this->ftpobj){
require_once 'Lyc/Ftp/Exception.class.php';
throw new Lyc_Ftp_Exception("FTP ERROR : Couldn't connect to $this->host");
}
}
/**
* 建立ssl ftp连接
*
*/
protected function connectSsl(){
$ftpobj=@ftp_ssl_connect($this->host,$this->port,$this->timeout);
if(null==$ftpobj){
require_once 'Lyc/Ftp/Exception.class.php';
throw new Lyc_Ftp_Exception("FTP ERROR : Couldn't connect to $this->host");
}
}
/**
* 登录验证ftp 及设置模式
*
*/
protected function login(){
if(@ftp_login($this->ftpobj,$this->user,$this->pwd)){
ftp_pasv($this->ftpobj,$pasv);
}else{
require_once 'Lyc/Ftp/Exception.class.php';
throw new Lyc_Ftp_Exception("FTP ERROR : Couldn't login to $this->host");
}
}
/**
* 上传文件
*
*/
public function upload($remotefile,$localfile){
}
/**
* 下载文件
*
*/
public function download($localfile,$remotefile){
}
/**
* 关闭连接
*
*/
public function close(){
if(is_string($this->ftpobj)){
ftp_close($this->ftpobj);
}
}
}
?>
|
二、LycFtpFtp.class.php 实现类
代码如下 |
复制代码 |
<?php
/* author:凹凸曼(lyc)
/* email: jar-c@163.com
/* time : 2011-04-22
/*
*/
require_once 'Lyc/Ftp/Abstract.class.php';
class Lyc_Ftp_Ftp extends Lyc_Ftp_Abstract{
public function __construct($host,$user,$pwd,$mode=FTP_BINARY,$port=21,$timeout=90,$pasv=TRUE){
$this->host=$host;
$this->user=$user;
$this->pwd=$pwd;
$this->mode=$mode;
$this->port=$port;
$this->timeout=$timeout;
$this->pasv=$pasv;
$this->init();
}
protected function init(){
$this->connect();
$this->login();
}
/**
* 上传文件
*
*/
public function upload($remotefile,$localfile){
$res=ftp_nb_put($this->ftpobj,$remotefile,$localfile,$this->mode,ftp_size($this->ftpobj,$remotefile));
while($res==FTP_MOREDATA){
$res=ftp_nb_continue($this->ftpobj);
}
if($res!=FTP_FINISHED){
return FALSE;
}
return TRUE;
}
/**
* 下载文件
*
*/
public function download($localfile,$remotefile){
ftp_set_option($this->ftpobj,FTP_AUTOSEEK,FALSE);
$res=ftp_nb_get($this->ftpobj,$localfile,$remotefile,$this->mode,ftp_size($this->ftpobj,$localfile));
while($res==FTP_MOREDATA){
$res=ftp_nb_continue($this->ftpobj);
}
if($res!=FTP_FINISHED){
return FALSE;
}
return TRUE;
}
}
?>
|
三、LycException.class.php 异常基类
代码如下 |
复制代码 |
<?php
/* author:凹凸曼(lyc)
/* email: jar-c@163.com
/* time : 2011-04-22
/*
*/
class Lyc_Exception extends Exception{
}
?>
|
四、LycFtpException.class.php FTP异常类
代码如下 |
复制代码 |
<?php
/* author:凹凸曼(lyc)
/* email: jar-c@163.com
/* time : 2011-04-22
*/
require_once 'Lyc/Exception.class.php';
class Lyc_Ftp_Exception extends Lyc_Exception{
}
?>
|
五、测试区
代码如下 |
复制代码 |
<?php
/**
* 上传文件
*
*/
public function uploadTest(){
require_once 'Lyc/Ftp/Ftp.class.php';
$host=23.64.41.13'; //主机
$user='tguser'; //用户名
$pwd=""; //密码 端口默认21 也可改
$ftp=new Lyc_Ftp_Ftp($host,$user,$pwd);
$res=$ftp->upload('test.rar',"F:\wwwroot\testarea\Lyc\Test\test.rar");
if(!$res){
echo " upload failure";
}
}
public function downloadTest(){
require_once 'Lyc/Ftp/Ftp.class.php';
$host=33.64.41.135';
$user='tguser';
$pwd="";
$ftp=new Lyc_Ftp_Ftp($host,$user,$pwd);
$res=$ftp->download("c:\test.rar","test.rar");
if(!$res){
echo "download failure";
}
}
|
标签:[!--infotagslink--]