Home > php教程 > php手册 > php 网页ftp 代码四 下载文件

php 网页ftp 代码四 下载文件

WBOY
Release: 2016-06-13 10:09:54
Original
1134 people have browsed it

php 网页ftp 代码四 下载文件

    $ftpserver=$_POST[ftpserver];
    $ftpport=$_POST[ftpport];
    $ftpuser=$_POST[ftpuser];
    $ftppassword=$_POST[ftppassword];
    $ftp=@ftp_connect($ftpserver,$ftpport);
    if(!$ftp){ echo "连接FTP服务器".$ftpserver."的端口".$ftpport."失败";exit;}
    $rs=@ftp_login($ftp,$ftpuser,$ftppassword);
    if(!$rs){ echo "用户名或密码错误,连接FTP服务器失败";exit;}
    $targetDir=str_replace("\\","/",stripslashes($_POST[targetDir]));
    $filename=substr(strrchr($_POST[filelist],"/"),1);
    echo $filename;
//    exit;
    if(substr($targetDir,strlen($targetDir)-1)=="/")
    {
     $rs=@ftp_get($ftp,$targetDir.$filename,$_POST[filelist],FTP_ASCII);
    }else{
     $rs=@ftp_get($ftp,$targetDir."/".$filename,$_POST[filelist],FTP_ASCII);
    }
    if($rs)
    {
     if(substr($targetDir,strlen($targetDir)-1)=="/")
     {
      echo "<script>alert('文件下载成功,文件在本机中路径为[".$targetDir.$filename."]');window.close();</script>";
     }else{
      echo "<script>alert('文件下载成功,文件在本机中路径为[".$targetDir."/".$filename."]');window.close();</script>";
     }
     exit;我是
    }else{
     echo "<script>alert('文件下载失败,请检查目标文件夹是否存在,源文件为[".$_POST[filelist]."]');window.close();</script>";
     exit;
    }
?>

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