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.

$file = base64_decode($_GET['file']);
if($file === '' || !isset($file)){
  echo "Sorry, file not found.";
    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');

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


1 Answer 1


This change is untested:

if( $file === '' || ! isset( $file ) || ! file_exists( $file ) ) {
  • Earlier I reported that it worked but I spoke too soon. While that worked when the file was not present, it also returned the same result when the file was present. Meaning, regardless of file availability, it was returning the "Sorry" page. db.tt/GB7VmvUG Commented Jan 29, 2016 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.