transparencia Posted February 4, 2010 Share Posted February 4, 2010 I want this code to force an SWF file to open on the browser but it doesn't display it right, like parts of the SWF files are missing. Can anybody help in tracking the problem? function _uc_file_download_transfer($file_user, $ip) { // Check if any hook_file_transfer_alter calls alter the download. foreach (module_implements('file_transfer_alter') as $module) { $name = $module .'_file_transfer_alter'; $file_user->full_path = $name($file_user, $ip, $fid, $file_user->full_path); } // This could get clobbered, so make a copy. $filename = $file_user->filename; // Gather relevant info about the file. $size = filesize($file_user->full_path); $fileinfo = pathinfo($file_user->full_path); $mimetype = file_get_mimetype($filename); // Workaround for IE filename bug with multiple periods / multiple dots in filename // that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { $filename = preg_replace('/\./', '%2e', $fileinfo['basename'], substr_count($fileinfo['basename'], '.') - 1); } else { $filename = $fileinfo['basename']; } // 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 // See http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt list($range, $extra_ranges) = explode(',', $range_orig, 2); } else { $range = ''; } } else { $range = ''; } // Figure out download piece from range (if set) list($seek_start, $seek_end) = explode('-', $range, 2); // Set start and end based on range (if set), else set defaults and check for invalid ranges. $seek_end = intval((empty($seek_end)) ? ($size - 1) : min(abs(intval($seek_end)), ($size - 1))); $seek_start = intval((empty($seek_start) || $seek_end < abs(intval($seek_start))) ? 0 : max(abs(intval($seek_start)), 0)); ob_end_clean(); //Only send partial content header if downloading a piece of the file (IE workaround) if ($seek_start > 0 || $seek_end < ($size - 1)) { drupal_set_header('HTTP/1.1 206 Partial Content'); } // Standard headers, including content-range and length drupal_set_header('Pragma: public'); drupal_set_header('Cache-Control: cache, must-revalidate'); drupal_set_header('Accept-Ranges: bytes'); drupal_set_header('Content-Range: bytes '. $seek_start .'-'. $seek_end .'/'. $size); drupal_set_header('Content-Type: '. $mimetype); drupal_set_header('Content-Disposition: inline; filename="'. $filename .'"'); drupal_set_header('Content-Length: '. ($seek_end - $seek_start + 1)); // Last-modified is required for content served dynamically drupal_set_header('Last-modified: '. format_date(filemtime($file_user->full_path), 'large')); // Etag header is required for Firefox3 and other managers drupal_set_header('ETag: '. md5($file_user->full_path)); // Open the file and seek to starting byte $fp = fopen($file_user->full_path, 'r'); fseek($fp, $seek_start); // Start buffered download while (!feof($fp)) { // Reset time limit for large files set_time_limit(0); // Push the data to the client. print(fread($fp, UC_FILE_BYTE_SIZE)); flush(); ob_flush(); } // Finished serving the file, close the stream and log the download to the user table fclose($fp); _uc_file_log_download($file_user, $ip); } Link to comment https://forums.phpfreaks.com/topic/190984-any-idea-why-this-code-doesnt-output-an-swf-file-correctly/ Share on other sites More sharing options...
transparencia Posted February 5, 2010 Author Share Posted February 5, 2010 Is there any problem in opening a SWF trough a buffered transfer? This is what is happening: // Open the file and seek to starting byte $fp = fopen($file_user->full_path, 'r'); fseek($fp, $seek_start); // Start buffered download while (!feof($fp)) { // Reset time limit for large files set_time_limit(0); // Push the data to the client. print(fread($fp, UC_FILE_BYTE_SIZE)); flush(); ob_flush(); } How can I change this to make a normal transfer, an un-buffered download? Link to comment https://forums.phpfreaks.com/topic/190984-any-idea-why-this-code-doesnt-output-an-swf-file-correctly/#findComment-1007467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.