Create Attachment Viewer Links

Posted on Thursday, December 4th, 2008 at 12:50 pm in

Create links to freely available plugins/applications for attachment files based upon the attachment MIME type.


<?php // Create viewer link based on an attachment mime type
$download='';
switch (true) {
	case (stristr($post->post_mime_type,'pdf')):
	$download = '<a href="http://www.adobe.com/products/acrobat/readstep2.html">Adobe Acrobat Reader</a>';
	break;

	case (stristr($post->post_mime_type,'msword')):
	$download = 'Microsoft<sup>®</sup> Word or <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=95e24c87-8732-48d5-8689-ab826e7b8fdf">Word Viewer 2003</a>';
	break;

	case (stristr($post->post_mime_type,'excel')):
	$download = 'Microsoft<sup>®</sup> Excel or <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c8378bf4-996c-4569-b547-75edbd03aaf0">Excel Viewer 2003</a>';
	break;

	case (stristr($post->post_mime_type,'powerpoint')):
	$download = 'Microsoft<sup>®</sup> Powerpoint or <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=428D5727-43AB-4F24-90B7-A94784AF71A4">Powerpoint Reader</a>';
	break;

	case (stristr($post->post_mime_type,'quicktime')):
	$download = '<a href="http://www.apple.com/quicktime/download/">Quicktime</a>';
	break;
}
if($download !='') echo '<p><small>This file requires '.$download.'.</small></p>';
?>

Output Example

This file requires Adobe Acrobat Reader

You might also be interested in

Add your comment

Leave a Reply

Leave A Comment


WordPress eShop CSS Themes - £9.95

Top