Redirect download hide file location

Hi,

I am selling a digital product and want to hide the true location of the download.

So I’m using a redirect script like this;

protected function redirectDownload ($realfilename) {
		ob_start();
		$mm_type="application/octet-stream";
		
		header("Cache-Control: public, must-revalidate");
		header("Pragma: no-cache");
		header("Content-Type: " . $mm_type);
		header("Content-Length: " .(string)(filesize($realfilename)) );
		header('Content-Disposition: attachment; filename="'.$this->fakefilename.'"');
		header("Content-Transfer-Encoding: binary\
");
		
		ob_end_clean();
		readfile($realfilename);
	}

The zip file is always corrupted when I download it, but when I download it directly it is fine.

Does anyone know why this might be?

I think this was working fine on another server, but would need to confirm that.

If I can’t solve this, is there any other techniques or services I can use to do this?

Thanks
James

protected function redirectDownload ($realfilename) {
        $mm_type="application/octet-stream";
        ob_start();     
        header("Cache-Control: public, must-revalidate");
        header("Pragma: no-cache");
        header("Content-Type: " . $mm_type);
        header("Content-Length: " .(string)(filesize($realfilename)) );
        header('Content-Disposition: attachment;
        filename="'.$this->fakefilename.'"');
        header("Content-Transfer-Encoding: binary\
");  
        ob_end_clean();
        readfile($realfilename);
    }

Also make sure that the file path is definitely correct, this would result in a corrupt file