code/controllers/CDNSecureFileController.php
public function sendFile($file) {
        $reader = $file->reader();
        if (!$reader || !$reader->isReadable()) {
            return;
        }

		if(class_exists('SapphireTest', false) && SapphireTest::is_running_test()) {
			return $reader->read();
		}
        
        $type = HTTP::get_mime_type($file->Filename);
        $disposition = strpos($type, 'image') !== false ? 'inline' : 'attachment';

		header('Content-Description: File Transfer');
		// Quotes needed to retain spaces (http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download)
		header(sprintf('Content-Disposition: %s; filename="%s"', $disposition, basename($file->Filename)));
		header('Content-Length: ' . $file->FileSize);
		header('Content-Type: ' . $type);
		header('Content-Transfer-Encoding: binary');

		// Ensure we enforce no-cache headers consistently, so that files accesses aren't cached by CDN/edge networks
		header('Pragma: no-cache');
		header('Cache-Control: private, no-cache, no-store');
        
        increase_time_limit_to(0);

		// Clear PHP buffer, otherwise the script will try to allocate memory for entire file.
		while (ob_get_level() > 0) {
			ob_end_flush();
		}

		// Prevent blocking of the session file by PHP. Without this the user can't visit another page of the same
		// website during download (see http://konrness.com/php5/how-to-prevent-blocking-php-requests/)
		session_write_close();

        echo $reader->read();
		die();
	}
public function sendFile($file) {
        $reader = $file->reader();
        if (!$reader || !$reader->isReadable()) {
            return;
        }

		if(class_exists('SapphireTest', false) && SapphireTest::is_running_test()) {
			return $reader->read();
		}
        
        $type = HTTP::get_mime_type($file->Filename);
        $disposition = strpos($type, 'image') !== false ? 'inline' : 'attachment';

		header('Content-Description: File Transfer');
		// Quotes needed to retain spaces (http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download)
		header(sprintf('Content-Disposition: %s; filename="%s"', $disposition, basename($file->Filename)));
		header('Content-Length: ' . $file->FileSize);
		header('Content-Type: ' . $type);
		header('Content-Transfer-Encoding: binary');

		// Ensure we enforce no-cache headers consistently, so that files accesses aren't cached by CDN/edge networks
		header('Pragma: no-cache');
		header('Cache-Control: private, no-cache, no-store');
        
        increase_time_limit_to(0);

		// Clear PHP buffer, otherwise the script will try to allocate memory for entire file.
		while (ob_get_level() > 0) {
			ob_end_flush();
		}

		// Prevent blocking of the session file by PHP. Without this the user can't visit another page of the same
		// website during download (see http://konrness.com/php5/how-to-prevent-blocking-php-requests/)
		session_write_close();

        echo $reader->read();
		die();
	}
public function sendFile ( $ file ) { $ reader = $ file -> reader ( ) ; if ( ! $ reader || ! $ reader -> isReadable ( ) ) { return ; } if ( class_exists ( 'SapphireTest' , false ) && SapphireTest :: is_running_test ( ) ) { return $ reader -> read ( ) ; } $ type = HTTP :: get_mime_type ( $ file -> Filename ) ; $ disposition = strpos ( $ type , 'image' ) !== false ? 'inline' : 'attachment' ; header ( 'Content-Description: File Transfer' ) ; // Quotes needed to retain spaces (http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download) header ( sprintf ( 'Content-Disposition: %s; filename="%s"' , $ disposition , basename ( $ file -> Filename ) ) ) ; header ( 'Content-Length: ' . $ file -> FileSize ) ; header ( 'Content-Type: ' . $ type ) ; header ( 'Content-Transfer-Encoding: binary' ) ; // Ensure we enforce no-cache headers consistently, so that files accesses aren't cached by CDN/edge networks header ( 'Pragma: no-cache' ) ; header ( 'Cache-Control: private, no-cache, no-store' ) ; increase_time_limit_to ( 0 ) ; // Clear PHP buffer, otherwise the script will try to allocate memory for entire file. while ( ob_get_level ( ) > 0 ) { ob_end_flush ( ) ; } // Prevent blocking of the session file by PHP. Without this the user can't visit another page of the same // website during download (see http://konrness.com/php5/how-to-prevent-blocking-php-requests/) session_write_close ( ) ; echo $ reader -> read ( ) ; die ( ) ; }
Output file to the browser.
For performance reasons, we avoid SS_HTTPResponse and just output the contents instead.
Output file to the browser . For performance reasons we avoid SS_HTTPResponse and just output the contents instead .