- This topic is empty.
-
AuthorPosts
-
May 18, 2015 at 6:36 am #202499RoySajeebParticipant
i am using the following code to download files from the server:
<?phpignore_user_abort(true);
set_time_limit(0);function my_filesize($fp) {
$return = false;
if (is_resource($fp)) {
if (PHP_INT_SIZE < 8) {
// 32bit
if (0 === fseek($fp, 0, SEEK_END)) {
$return = 0.0;
$step = 0x7FFFFFFF;
while ($step > 0) {
if (0 === fseek($fp, – $step, SEEK_CUR)) {
$return += floatval($step);
} else {
$step >>= 1;
}
}
}
} elseif (0 === fseek($fp, 0, SEEK_END)) {
// 64bit
$return = ftell($fp);
}
}
return $return;
}$url = $_GET[‘path’];
$currentLocation = ‘http://’.$_SERVER[‘HTTP_HOST’];
$fileURL = ‘../../’.str_replace($currentLocation,”,$url);$fileSize = my_filesize(fopen($fileURL,’r’));
//echo $fileSize;
if (file_exists($fileURL)) {
header(‘Content-Description: File Transfer’);
header(‘Content-Type: application/octet-stream’);
header(‘Content-Disposition: attachment; filename=’.basename($fileURL));
header(‘Content-Transfer-Encoding: binary’);
header(‘Expires: 0’);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’);
header(‘Pragma: public’);
header(‘Content-Length: ‘.$fileSize);
ob_clean();
flush();
readfile($fileURL);
exit;
}?>
but the problem is that the line “header(‘Content-Length’)” does not return file sizes greater than 2GB even when the actual file size is 50GB, i am using php-5.5.9 and apache2 on Ubuntu 14.04.2 LTS. So, i was wondering if there’s a way to solve this problem. Thanks!
May 21, 2015 at 1:58 pm #202681oviParticipantyou can try the following function instead of
my_filesize()
:function remote_filesize($url) { static $regex = '/^Content-Length: *+Kd++$/im'; if (!$fp = @fopen($url, 'rb')) { return false; } if ( isset($http_response_header) && preg_match($regex, implode("n", $http_response_header), $matches) ) { return (int)$matches[0]; } return strlen(stream_get_contents($fp)); }
Source: http://php.net/manual/en/function.filesize.php#114952
May 23, 2015 at 5:51 pm #202772RoySajeebParticipantThe problem isn’t that i can’t get the file size… i can get the file size just right but i can’t send the file size to the user via header(‘content-length’)… direct download, however, on the other hand, without the php, works just fine…. if i remove header(‘Content-Length’) the user can download the entire file but cannot see the total size and if i leave it untouched the client can only download 2GB of the entire file… so, i tried installing 64bit OS, 64bit apache and 64bit php on my 32bit machine and everything works but then i cannot upload files greater than 2GB via blueimp Jquery File Uploader even when i change everything in apache.conf and both the php.ini files, /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini…. but when i try to upload anything greater than 2GB without blueimp, with just a simple file uploader, it works like a charm…. i can’t seem to figure out what’s happening with me….
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.