'Check if file does not have in shell server

I want to download file from shell server but if that file does not have in shell server it will display to user that not have file

        <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>

and my load file is

$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
}

I use phpseclib please suggest me what should I do.



Solution 1:[1]

You could do $sftp->file_exists($txtdownload).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 neubert