diff --git a/Makefile b/Makefile index a76e1cf579bf381e181c73de92ab358abae43758..ffe0ce3cd9781e519fb32131dee578c082dc7b0c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BASE=downloads_for_sale PLUGINTYPE=vmcustom -VERSION=1.5.3 +VERSION=1.5.4 PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html diff --git a/downloads_for_sale.php b/downloads_for_sale.php index bf6589a86d933b4f3a11e65e4b711bdb4ff8f1d2..5738b69e4b0c3793f7a2b50d9096961f7a0f6541 100644 --- a/downloads_for_sale.php +++ b/downloads_for_sale.php @@ -150,7 +150,32 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin { $this->parseCustomParams($field); return $field; } - + + // This readfile replacement comes from the php.net documentation of readfile (http://www.php.net/readfile), in particular flowbee@gmail.com and chrisputnam@gmail.com summarizing discussions @php-dev: + function readfile_chunked($filename, $retbytes=true) { + $chunksize = 1*(1024*1024); // how many bytes per chunk + $buffer = ''; + $cnt =0; + $handle = fopen($filename, 'rb'); + if ($handle === false) { + return false; + } + while (!feof($handle)) { + $buffer = fread($handle, $chunksize); + echo $buffer; + ob_flush(); + flush(); + if ($retbytes) { + $cnt += strlen($buffer); + } + } + $status = fclose($handle); + if ($retbytes && $status) { + return $cnt; // return num. bytes delivered like readfile() does. + } + return $status; + } + function downloadFile($media_id, &$output){ if ($media_id) { jimport('joomla.filesystem.file'); @@ -159,9 +184,11 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin { JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_DLSALE_ERROR_MEDIA_NOT_CONFIGURED', $media_id), 'error'); return false; } + flush(); + ob_flush(); header("Content-Type: " . $media->file_mimetype); header("Content-Disposition: attachment; filename=\"".JFile::getName($media->file_url)."\""); - if (@readfile($media->file_url)) { + if (@$this->readfile_chunked($media->file_url)) { return true; } else { header_remove("Content-Type"); diff --git a/downloads_for_sale.xml b/downloads_for_sale.xml index fd61d3f6b08c25dbad57c8b997d74bd66e5c6e7f..0d409eab57eae35fc278ce9699a83d8c2df9620b 100644 --- a/downloads_for_sale.xml +++ b/downloads_for_sale.xml @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="UTF-8" ?> <install version="1.5" type="plugin" group="vmcustom" method="upgrade"> <name>VMCUSTOM_DLSALE</name> - <creationDate>2013-02-08</creationDate> + <creationDate>2013-09-21</creationDate> <author>Reinhold Kainhofer</author> <authorUrl>http://www.open-tools.net/</authorUrl> <copyright>Copyright (C) 2013 Reinhold Kainhofer. All rights reserved.</copyright> <license>http://www.gnu.org/licenses/gpl.html GNU/GPL v3+</license> - <version>1.5.3</version> + <version>1.5.4</version> <description>VMCUSTOM_DLSALE_DESC</description> <files> <filename plugin="downloads_for_sale">downloads_for_sale.php</filename> diff --git a/releases/plg_vmcustom_downloads_for_sale_v1.5.4.zip b/releases/plg_vmcustom_downloads_for_sale_v1.5.4.zip new file mode 100644 index 0000000000000000000000000000000000000000..019ca0909ab9bc5e8e84b078318e9ddfce9237d1 Binary files /dev/null and b/releases/plg_vmcustom_downloads_for_sale_v1.5.4.zip differ