Saturday, August 13, 2011

Simple Trick to Find File Content Type in PHP

When processing file from server side we need a Exact document Content-Type header define required to process a content type properly.

From the following php header parameter have "Content-Type": audio/mpeg. The String "audio/mpeg" is the content type of the file which we need to process a proper format disposition from server to client.

header('Content-type: audio/mpeg');
Here is the Simple Trick to find the document Content-Type header string
<?php

if(isset($_POST['upload']))
{
	echo "<pre>";
	print_r($_FILES);
	echo "</pre>";
}

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Simple Trick to Find File Content Type in PHP</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data">

<input name="filename" type="file" />
<input type="submit" name="upload" value="Check Content Type" />

</form>
</body>
</html>



No comments:

Post a Comment