检查文件在shell服务器中是否没有

时间:2015-04-01 18:58:15

标签: php shell get phpseclib downloadfile

我想从shell服务器下载文件,但如果该文件没有在shell服务器中,它将显示给没有文件的用户

        <form class="cmxform form-horizontal tasi-form" name="frm" id="frm" method="post" enctype="multipart/form-data" action="loadfile.php" onsubmit="return validateForm();">
      <div class="form-group">
        <label class="col-sm-2 control-label">Full path of a file :</label>
        <div class="col-sm-5"><input type="text" class="form-control" name="download" required/></div>
          <input type="submit" id="submit" name="submit" class="btn btn-primary" value="Download" />
          <input type="reset" class="btn btn-danger" value="Cancel" />
        </div>
    </form>

我的加载文件是

$txtdownload = $_POST['download'];
$local_file = "report.txt"; //file name download
if($sftp->get($txtdownload,$local_file)){
header('Content-Length: '. filesize($local_file));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($local_file).'"');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
readfile($local_file); // send the file
exit;  // make sure no extraneous characters get appended
}

我使用phpseclib请告诉我该怎么做。

1 个答案:

答案 0 :(得分:0)

你可以$sftp->file_exists($txtdownload)