<?php require '../class/BigFileTools.php'; $size = BigFileTools::fromPath(__FILE__)->getSize(); var_dump($size); echo "Example files size is " . $size . " bytes\n";
function addFiles($files) { if (!is_array($files) || count($files) < 1) { return; } $free_attach = 1024 * 1024 * 20; foreach ($files as $file) { $filename = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . "support" . DS . $file->diskfile; require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'bigfiletools.php'; $f = BigFileTools::fromPath($filename); $file_size = $f->getSize(); if ($file_size < $free_attach) { $this->files[$filename] = $file->filename; $free_attach -= $file_size; } else { $this->skipped_files[$filename] = $file->filename; } } }
<?php require '../class/BigFileTools.php'; echo $f = BigFileTools::fromPath(__FILE__)->getSize() . " bytes";
function addFilesFromPost($message_id, $user_id = -1, $hide_from_user = 0) { // ADD ALL POSTED FILES TO THE TICKET if ($user_id == -1) { $user_id = JFactory::getUser()->id; } $files = array(); // save any file attachments for ($i = 0; $i < 10; $i++) { $file = JRequest::getVar('filedata_' . $i, '', 'FILES', 'array'); if (array_key_exists('error', $file) && $file['error'] == 0 && $file['name'] != '') { $destpath = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . 'support' . DS; $destname = FSS_File_Helper::makeAttachFilename("support", $file['name'], date("Y-m-d"), $this, $user_id); if (JFile::upload($file['tmp_name'], $destpath . $destname)) { $qry = "INSERT INTO #__fss_ticket_attach (ticket_ticket_id, filename, diskfile, size, user_id, added, message_id, hidefromuser) VALUES ('"; $qry .= FSSJ3Helper::getEscaped($db, $this->id) . "',"; $qry .= "'" . FSSJ3Helper::getEscaped($db, $file['name']) . "',"; $qry .= "'" . FSSJ3Helper::getEscaped($db, $destname) . "',"; $qry .= "'" . $file['size'] . "',"; $qry .= "'" . FSSJ3Helper::getEscaped($db, $user_id) . "',"; $qry .= "'" . FSS_Helper::CurDate() . "', {$message_id}, '" . FSSJ3Helper::getEscaped($db, $hide_from_user) . "' )"; echo $qry . "<br>"; $file_obj = new stdClass(); $file_obj->filename = $file['name']; $file_obj->diskfile = $destname; $file_obj->size = $file['size']; $files[] = $file_obj; $db->setQuery($qry); $db->Query(); SupportActions::DoAction_Ticket("addFile", $this, array('file' => $file_obj)); } } } // new style posted files using jquery file uploaded $post_files = JRequest::getVar('new_filename', 'POST', 'array'); $token = FSS_File_Helper::makeUploadSubdir(JRequest::getVar('upload_token')); if (is_array($post_files)) { foreach ($post_files as $file) { $destpath = JPATH_SITE . DS . FSS_Settings::get('attach_location') . DS . 'support' . DS; $destname = FSS_File_Helper::makeAttachFilename("support", $file, date("Y-m-d"), $this, $user_id); $source = JPATH_ROOT . '/tmp/fss/incoming/' . $token . '/' . $file; require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'bigfiletools.php'; $f = BigFileTools::fromPath($source); $size = $f->getSize(); $dest = $destpath . $destname; if (JFile::move($source, $dest)) { $qry = "INSERT INTO #__fss_ticket_attach (ticket_ticket_id, filename, diskfile, size, user_id, added, message_id, hidefromuser) VALUES ('"; $qry .= FSSJ3Helper::getEscaped($db, $this->id) . "',"; $qry .= "'" . FSSJ3Helper::getEscaped($db, $file) . "',"; $qry .= "'" . FSSJ3Helper::getEscaped($db, $destname) . "',"; $qry .= "'" . $size . "',"; $qry .= "'" . FSSJ3Helper::getEscaped($db, $user_id) . "',"; $qry .= "'" . FSS_Helper::CurDate() . "', {$message_id}, '" . FSSJ3Helper::getEscaped($db, $hide_from_user) . "' )"; $file_obj = new stdClass(); $file_obj->filename = $file; $file_obj->diskfile = $destname; $file_obj->size = $size; $files[] = $file_obj; $db->setQuery($qry); $db->Query(); SupportActions::DoAction_Ticket("addFile", $this, array('file' => $file_obj)); } } } if (is_dir(JPATH_ROOT . '/tmp/fss/incoming/' . $token)) { @rmdir(JPATH_ROOT . '/tmp/fss/incoming/' . $token); } FSS_File_Helper::CleanupIncoming(); if (count($files) < 1) { return false; } return $files; }
static function DownloadFile($filename, $display_name, $ext = "") { // TODO: We need a much better piece of code for downloading files here // it will end up being used for large attachments etc so needs to work with big files! if ($ext == "") { $ext = pathinfo($display_name, PATHINFO_EXTENSION); } $ctype = FSS_Helper::datei_mime($ext); ob_end_clean(); while (ob_get_level() > 0) { ob_end_clean(); } ini_set('zlib.output_compression', 'Off'); ini_set('output_buffering', 'Off'); ini_set('output_handler', ''); if (function_exists("apache_setenv")) { apache_setenv('no-gzip', 1); } require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'bigfiletools.php'; $f = BigFileTools::fromPath($filename); $file_size = $f->getSize(); header("Pragma: no-cache"); header("Expires: -1"); header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0"); header("Content-Type: " . $ctype); header("Content-Disposition: attachment; filename=\"{$display_name}\""); //check if http_range is sent by browser (or download manager) if (isset($_SERVER['HTTP_RANGE'])) { list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2); if ($size_unit == 'bytes') { //multiple ranges could be specified at the same time, but for simplicity only serve the first range //http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt list($range, $extra_ranges) = explode(',', $range_orig, 2); } else { $range = ''; header('HTTP/1.1 416 Requested Range Not Satisfiable'); exit; } } else { $range = ''; } //figure out download piece from range (if set) if ($range && strpos($range, "-") !== false) { list($seek_start, $seek_end) = @explode('-', $range, 2); } else { $seek_start = 0; $seek_end = 0; } //set start and end based on range (if set), else set defaults //also check for invalid ranges. $seek_end = empty($seek_end) ? $file_size - 1 : min(abs(intval($seek_end)), $file_size - 1); $seek_start = empty($seek_start) || $seek_end < abs(intval($seek_start)) ? 0 : max(abs(intval($seek_start)), 0); //Only send partial content header if downloading a piece of the file (IE workaround) if ($seek_start > 0 || $seek_end < $file_size - 1) { header('HTTP/1.1 206 Partial Content'); header('Content-Range: bytes ' . $seek_start . '-' . $seek_end . '/' . $file_size); header('Content-Length: ' . ($seek_end - $seek_start + 1)); } else { header("Content-Length: {$file_size}"); } set_time_limit(0); $file = fopen($filename, "rb"); while (!feof($file)) { echo @fread($file, 1024 * 256); @ob_flush(); @flush(); if (connection_status() != 0) { @fclose($file); exit; } } @fclose($file); exit; }
protected function get_file_size($file_path, $clear_stat_cache = false) { if ($clear_stat_cache) { if (version_compare(PHP_VERSION, '5.3.0') >= 0) { clearstatcache(true, $file_path); } else { clearstatcache(); } } require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'bigfiletools.php'; try { $f = BigFileTools::fromPath($file_path); return $f->getSize(); } catch (exception $e) { return 0; } //return $this->fix_integer_overflow(filesize($file_path)); }
/** * Function that determines a file's size only with PHP functions, * for all files, also those > 4 GB: * @see http://www.php.net/manual/en/function.filesize.php#102135 * @param string $file * @return float */ public static function filesize($file) { return BigFileTools::fromPath($file)->getSize(true); }