Post by Webnet » Thu May 31, 2012 8:26 pm

If the download available for a product is greater than 2GB filesize() will throw an error when downloading. We sell MP3s of sermons that have been preached over a 40 year period. We offer individual as well as bulk.

The 2GB limit is mentioned several times in PHP's contributed notes: http://ru.php.net/manual/en/function.fi ... php#100434

On my current installation I've worked around this using.... but I'm sure there's a better command-line based method for getting the filesize.

Code: Select all

			foreach ($results as $result) {
				if (file_exists(DIR_DOWNLOAD . $result['filename'])) {
					//PREVENT LARGE FILES FROM USING filesize()
					if (strstr($result['name'], "Sermon MP3 Downloads")) {
						$this->data['downloads'][] = array(
							'order_id'   => $result['order_id'],
							'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
							'name'       => $result['name'],
							'remaining'  => $result['remaining'],
							'size'       => ' > 2GB',
							'href'       => HTTPS_SERVER . 'index.php?route=account/download/download&order_download_id=' . $result['order_download_id']
						);
					} else {
						$size = filesize(DIR_DOWNLOAD . $result['filename']);
					
						$i = 0;
	
						$suffix = array(
							'B',
							'KB',
							'MB',
							'GB',
							'TB',
							'PB',
							'EB',
							'ZB',
							'YB'
						);
	
						while (($size / 1024) > 1) {
							$size = $size / 1024;
							$i++;
						}
	
						$this->data['downloads'][] = array(
							'order_id'   => $result['order_id'],
							'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
							'name'       => $result['name'],
							'remaining'  => $result['remaining'],
							'size'       => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
							'href'       => HTTPS_SERVER . 'index.php?route=account/download/download&order_download_id=' . $result['order_download_id']
						);
					}
				}
			}

New member

Posts

Joined
Fri Dec 31, 2010 3:17 am
Who is online

Users browsing this forum: No registered users and 16 guests