كيف يمكنني تقديم ملف xml مضغوط بطريقة gzip للتحميل باستخدام PHP

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

  •  03-07-2019
  •  | 
  •  

سؤال

ولدي النصي PHP أن يخلق ملف xml من ديسيبل. وأود أن يكون السيناريو خلق بيانات 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
?>

إذا لم يكن لديك غزيب حدة المتاحة،

<?php

  system('gzip filename.xml');

?>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top