Home  >  Article  >  Backend Development  >  Query whether a certain pdf file exists in the server

Query whether a certain pdf file exists in the server

WBOY
WBOYOriginal
2016-09-19 09:16:311266browse

Dear masters, please provide a query to see if a certain pdf file exists in the server. If it exists, it will be opened. If it does not exist, the user will be prompted to re-enter.

Reply content:

Dear masters, please provide a query to see if a certain pdf file exists in the server. If it exists, it will be opened. If it does not exist, the user will be prompted to re-enter.

Make a judgment first and then perform the corresponding operation.

<code>$fileName = "text.pdf";
if(file_exists($fileName)) {
    Header("Location: $fileName"); 
} else {
    echo  '<script> alert("文件不存在") </script>';
    //die(json_encode(array("code"=> 404, "message"=> "文件不存在")));
}</code>
Statement:
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