0

To have an address as a wordpress page like https://example.com/download, I created a php file in custom plugin to download test.pdf file and use it as wordpress shortcode inside the mentioned page, additionally my pdf file is in followed address: https://example.com/wp-content/uploads/test.pdf. Even though browser loads this url well, in script environment the file_exist returns false and I can not load the pdf file by loading https://example.com/download address

$upload_dir     = wp_upload_dir();
$upload_basedir = $upload_dir['basedir'];
$file           = $upload_basedir . '/test.pdf';

if(file_exists($file)) {
    // header("Content-Type: application/octet-stream"); 
    header("Content-type : application/pdf");
    header("Content-Disposition : attachment; filename='test.pdf'");
    header("Content-Length: " . filesize("test.pdf"));
    readfile($file);                            
    die;    
}
  • 1
    Did you try something from here https://stackoverflow.com/questions/981954/how-can-one-check-to-see-if-a-remote-file-exists-using-php or https://stackoverflow.com/questions/7684771/how-to-check-if-a-file-exists-from-a-url – Ihor Vyspiansky Aug 07 '20 at 09:51

0 Answers0