PHP를 사용하여 다운로드 할 gzipped XML 파일을 어떻게 제공 할 수 있습니까?

StackOverflow https://stackoverflow.com/questions/605335

  •  03-07-2019
  •  | 
  •  

문제

DB에서 XML 파일을 만드는 PHP 스크립트가 있습니다. 스크립트가 XML 데이터를 만들고 즉시 .gzip 파일을 다운로드 할 수 있도록하고 싶습니다. 나에게 몇 가지 아이디어를 주시겠습니까?

감사!

도움이 되었습니까?

해결책

GZIP 압축을 쉽게 적용 할 수 있습니다 Gzencode 기능.

<?
header("Content-Disposition: attachment; filename=yourFile.xml.gz");
header("Content-type: application/x-gzip");

echo gzencode($xmlToCompress);

다른 팁

이 같은?

<?php
 header('Content-type: application/x-gzip');
 header('Content-Disposition: attachment; filename="downloaded.gz"');
 $data = implode("", file('somefile.xml'));
 print( gzencode($data, 9) ); //9 is the level of compression
?>

당신이 없다면 GZIP 모듈 사용 가능,

<?php

  system('gzip filename.xml');

?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top