Great Minds Do Not Think Alike

Monitor Resolution

Forum Index Members Search Usergroups
Ranks Staff Statistics Forum FAQ
Board Rules Edit your profile Login, Check Messages Log in

Search for at

 
Recent Topics     
Forum Replies Last Post
Force Downloads by setting the correct mime type.
Started by Admin
PHP Uploading & Downloading 0 Mon Jul 29, 2019 6:19 am
by Admin
Facebook SDK for PHP (v5)
Started by Admin
facebook/php-graph-sdk v5 0 Mon Jul 22, 2019 9:46 pm
by Admin
Welcome to PHP-Nuke Titanium v3.0.0!
Started by Admin
Current Version 0 Tue Jul 14, 2009 12:22 am
by Admin

Force Downloads by setting the correct mime type.
Post new topic Reply to topic printer-friendly view List users that have viewed this topic Thank Post Forum Index PHP Uploading & Downloading
View previous topic View next topic
PostPosted: Mon Jul 29, 2019 6:19 am Reply with quote
Admin
force-download.php

PHP:  [ Select all ]

/**
 * Force Download
 *
 * Generates headers that force a download to happen
 * Example usage:
 * force_download( 'screenshot.png', './images/screenshot.png' );
 *
 * @access public
 * @param string $filename
 * @param string $data
 * @return void
 */
function force_download$filename ''$data '' )
{
 
   if$filename == '' || $data == '' )
 
   {
 
       return false;
 
   }
 
   
    if
( !file_exists$data ) )
 
   {
 
       return false;
 
   }

 
   // Try to determine if the filename includes a file extension.
 
   // We need it in order to set the MIME type
 
   iffalse === strpos$filename'.' ) )
 
   {
 
       return false;
 
   }

 
   // Grab the file extension
 
   $extension strtolowerpathinfobasename$filename ), PATHINFO_EXTENSION ) );

 
   // our list of mime types
 
   $mime_types = array(

 
       'txt' => 'text/plain',
 
       'htm' => 'text/html',
 
       'html' => 'text/html',
 
       'php' => 'text/html',
 
       'css' => 'text/css',
 
       'js' => 'application/javascript',
 
       'json' => 'application/json',
 
       'xml' => 'application/xml',
 
       'swf' => 'application/x-shockwave-flash',
 
       'flv' => 'video/x-flv',

 
       // images
 
       'png' => 'image/png',
 
       'jpe' => 'image/jpeg',
 
       'jpeg' => 'image/jpeg',
 
       'jpg' => 'image/jpeg',
 
       'gif' => 'image/gif',
 
       'bmp' => 'image/bmp',
 
       'ico' => 'image/vnd.microsoft.icon',
 
       'tiff' => 'image/tiff',
 
       'tif' => 'image/tiff',
 
       'svg' => 'image/svg+xml',
 
       'svgz' => 'image/svg+xml',

 
       // archives
 
       'zip' => 'application/zip',
 
       'rar' => 'application/x-rar-compressed',
 
       'exe' => 'application/x-msdownload',
 
       'msi' => 'application/x-msdownload',
 
       'cab' => 'application/vnd.ms-cab-compressed',

 
       // audio/video
 
       'mp3' => 'audio/mpeg',
 
       'qt' => 'video/quicktime',
 
       'mov' => 'video/quicktime',

 
       // adobe
 
       'pdf' => 'application/pdf',
 
       'psd' => 'image/vnd.adobe.photoshop',
 
       'ai' => 'application/postscript',
 
       'eps' => 'application/postscript',
 
       'ps' => 'application/postscript',

 
       // ms office
 
       'doc' => 'application/msword',
 
       'rtf' => 'application/rtf',
 
       'xls' => 'application/vnd.ms-excel',
 
       'ppt' => 'application/vnd.ms-powerpoint',

 
       // open office
 
       'odt' => 'application/vnd.oasis.opendocument.text',
 
       'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
 
   );

 
   // Set a default mime if we can't find it
 
   if( !isset( $mime_types[$extension] ) )
 
   {
 
       $mime 'application/octet-stream';
 
   }
 
   else
    
{
 
       $mime = ( is_array$mime_types[$extension] ) ) ? $mime_types[$extension][0] : $mime_types[$extension];
 
   }
 
       
    
// Generate the server headers
 
   ifstrstr$_SERVER['HTTP_USER_AGENT'], "MSIE" ) )
 
   {
 
       header'Content-Type: "'.$mime.'"' );
 
       header'Content-Disposition: attachment; filename="'.$filename.'"' );
 
       header'Expires: 0' );
 
       header'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
 
       header"Content-Transfer-Encoding: binary" );
 
       header'Pragma: public' );
 
       header"Content-Length: ".filesize$data ) );
 
   }
 
   else
    
{
 
       header"Pragma: public" );
 
       header"Expires: 0" );
 
       header"Cache-Control: must-revalidate, post-check=0, pre-check=0" );
 
       header"Cache-Control: private"false );
 
       header"Content-Type: ".$mimetrue200 );
 
       header'Content-Length: '.filesize$data ) );
 
       header'Content-Disposition: attachment; filename='.$filename);
 
       header"Content-Transfer-Encoding: binary" );
 
   }
 
   readfile$data );
 
   exit;

//End force_download 

 
Please login to see this link
Get registered or Log in


Sincerely,
Ernest Allen Buffington
813-846-2865

Site Owner

Groups Site Owner
Posts 3
Joined Jul 17, 2019
Status Offline
Gender Male
View user's profile Send Admin a private message Visit user's website Find all posts by Admin

Display posts from previous:
Post new topic Reply to topic printer-friendly view List users that have viewed this topic Thank Post All times are UTC + 10 Hours
Page 1 of 1


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001, 2019 phpBB Group
CarbinFiber Red Flames Designed By: TheGhost © 2019 The 86it Developers Network