I have a custom plugin that was developed for me a while back and I'm trying to tweak it's action and fix a slight bug.
Based on certain conditions, the plugin presents the user with a custom url/link to a zip file to download. It masks the file location before downloading to hide location from user. It works fine under normal circumstances: If user has file assigned to them, link to download file is presented and it downloads the zip file via browser fine. But if the file does not exist, a junk / malformed zip/html file is downloaded instead.
I want the screen to simply display "Sorry, File Not found" - nothing else.
This is the code that is currently provided in the download mask file.
<?php
/**
*
**/
$file = base64_decode($_GET['file']);
if($file === '' || !isset($file)){
echo "Sorry, file not found.";
die();
}else{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile($file);
exit;
}
This is contents the malformed file that is downloaded instead.
<br />
<b>Warning</b>: readfile(http://{domain(dot)com/{somedirectory}/{somefilename}.zip): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
in <b>/home/{account}/public_html/wp-content/plugins/{customplugin}/downloadmask.php</b> on line <b>18</b><br />
Someone said it's because I have PHP warnings and notices enabled? Dunno, I'm a noobie/hack when it comes to PHP - only know enough to probably get myself in trouble. But I want to learn :)
Thanks.