What is the best way to get a digital product loaded in PHP?

Digital commercial products that customers pay for a download link.

I put all the zipped files (products) outside the root of the web document, and buyers download them through a php script that integrates with paypal IPN to make sure that the bootloader is a paying buyer.

View like: http://www.mysite.com/download.php?buyer_id=xxx

So far, everything works with only one problem. The zip files downloaded at the above URL are corrupted and cannot be opened correctly using WinRAR. However, the directly downloaded zip is ok.

My code is:

$path = WAREHOUSE_PATH.'/products/'.$identifier.'.zip';
$mm_type="application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");

$fp = @fopen($path,"rb");
if ($fp) {
  while(!feof($fp)) {
    print(fread($fp, 1024*8));
    flush();
    if (connection_status()!=0) {
      @fclose($fp);
      die();
    }
  }
  @fclose($fp);
}

What could be wrong? Thanks!

: . , , . .

+3
3

readfile(). ignore_user_abort, script , .

, .

+2

:

$fp = @fopen($path,"rb");
if ($fp) {
  while(!feof($fp)) {
    print(fread($fp, 1024*8));
    flush();
    if (connection_status()!=0) {
      @fclose($fp);
      die();
    }
  }
  @fclose($fp);
}

readfile($path);

readfile , , .

+3

Content-Transfer-Encoding - , ?

+2

Source: https://habr.com/ru/post/1702298/


All Articles