php get file mime type

Solutions on MaxInterview for php get file mime type by the best coders in the world

showing results for - "php get file mime type"
Andrea
05 Aug 2017
1$fileSizeInBytes=filesize("/path/to/myfile.txt"); 
Michelle
12 Nov 2018
1echo mime_content_type("yourfile.gif"); //image/gif
Irene
23 Aug 2016
1<?php
2echo filetype('/etc/passwd');  // file
3echo filetype('/etc/');        // dir
4?>
5
6
Andrea
19 Jan 2019
1function get_content_mime_type($content)
2{
3  $url = 'http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types';
4  $url_live = false;
5  $handle = curl_init($url);
6  curl_setopt_array($handle, array(
7    CURLOPT_FOLLOWLOCATION => true,
8    CURLOPT_NOBODY => true,
9    CURLOPT_HEADER => false,
10    CURLOPT_RETURNTRANSFER => false,
11    CURLOPT_SSL_VERIFYHOST => false,
12    CURLOPT_SSL_VERIFYPEER => false
13  ));
14  $response = curl_exec($handle);
15  $httpCode = curl_getinfo($handle, CURLINFO_EFFECTIVE_URL);
16  $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
17  if ($httpCode == 200)
18  {
19    $url_live = true;
20  }
21  $url_live = $url_live;
22  curl_close($handle);
23  $mimes = array();
24  if ($url_live)
25  {
26    $mimes_file = file_get_contents($url);
27    preg_match_all('#^([^\s]{2,}?)\s+(.+?)$#ism', $mimes_file, $matches, PREG_SET_ORDER);
28    foreach ($matches as $match)
29    {
30      $exts = explode(" ", $match[2]);
31      foreach ($exts as $ext)
32      {
33        $mimes[$ext] = $match[1];
34      }
35    }
36  }
37  else
38  {
39    $mimes = array(
40      'txt' => 'text/plain',
41      'htm' => 'text/html',
42      'html' => 'text/html',
43      'php' => 'text/html',
44      'css' => 'text/css',
45      'js' => 'application/javascript',
46      'json' => 'application/json',
47      'xml' => 'application/xml',
48      'swf' => 'application/x-shockwave-flash',
49      'flv' => 'video/x-flv',
50      // images
51      'png' => 'image/png',
52      'jpe' => 'image/jpeg',
53      'jpeg' => 'image/jpeg',
54      'jpg' => 'image/jpeg',
55      'gif' => 'image/gif',
56      'bmp' => 'image/bmp',
57      'ico' => 'image/vnd.microsoft.icon',
58      'tiff' => 'image/tiff',
59      'tif' => 'image/tiff',
60      'svg' => 'image/svg+xml',
61      'svgz' => 'image/svg+xml',
62      // archives
63      'zip' => 'application/zip',
64      'rar' => 'application/x-rar-compressed',
65      'exe' => 'application/x-msdownload',
66      'msi' => 'application/x-msdownload',
67      'cab' => 'application/vnd.ms-cab-compressed',
68      // audio/video
69      'mp3' => 'audio/mpeg',
70      'qt' => 'video/quicktime',
71      'mov' => 'video/quicktime',
72      // adobe
73      'pdf' => 'application/pdf',
74      'psd' => 'image/vnd.adobe.photoshop',
75      'ai' => 'application/postscript',
76      'eps' => 'application/postscript',
77      'ps' => 'application/postscript',
78      // ms office
79      'doc' => 'application/msword',
80      'rtf' => 'application/rtf',
81      'xls' => 'application/vnd.ms-excel',
82      'ppt' => 'application/vnd.ms-powerpoint',
83      'docx' => 'application/msword',
84      'xlsx' => 'application/vnd.ms-excel',
85      'pptx' => 'application/vnd.ms-powerpoint',
86      // open office
87      'odt' => 'application/vnd.oasis.opendocument.text',
88      'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
89    );
90  }
91  $content_mime = 'unknown';
92  if (is_file($content))
93  {
94    if (isset(pathinfo($content) ['extension']))
95    {
96      $content_ext = pathinfo($content) ['extension'];
97      if (isset($mimes[$content_ext]))
98      {
99        $content_mime = $mimes[$content_ext];
100      }
101      else
102      {
103        if (is_readable($content) && is_executable($content))
104        {
105          $finfo = finfo_open(FILEINFO_MIME_TYPE);
106          $content_mime = finfo_file($finfo, $content);
107          if ($content_mime === null | $content_mime === "")
108          {
109            $content_mime = "application/octet-stream";
110          }
111          else
112          {
113            $content_mime = $content_mime;
114          }
115          finfo_close($finfo);
116        }
117        else
118        {
119          $content_mime = "application/octet-stream";
120        }
121      }
122    }
123  }
124  else
125  {
126    // return whatever you want
127    // $content_mime = 'unknown';
128
129  }
130  $content_mime = $content_mime;
131  return $content_mime;
132}
133
queries leading to this page
php get file mimephp get mime type from file namephp get size of documentget size of file phpphp get filetypephp get the typeget a file size with phpwhat functions should not be used in loop of php applications 3f filesizeget file content type in phpphp get folder of current filephp get filetypcheck file size php uploadphp download file mime typephp glob file size in kbget file size phpfind file size by file content in phpget the file in php in storage and get the mime typeget file uploaded size phpknow file type phpphp get file size 0 kbget size file with phpphp get file size from content stringphp get file siuzephp get file type from pathget file size php after getting file contentsphp get mime type of filephp get filetyepget file size url phpget size of raw file data phpphp 24 file sizephp get file size in mbjs get file size like php size formatget size or file php file contentsphp get uploaded file mime typemulter set file size limitphp file size checkfind file size in phpphp how to upload 10mb txt file to servercheck file size phpget file type using phpfile get content phphow to get file size in phpgetting a file size from path in the serverget mimetype of file phpyou need to check the size of a file in php function 24size 3d x 28filename 29 3b which function will sizesuitably replace 27x 27 3f1024 2a 1024 2a 10 file size phpget file length uploaded phpphp file typephp get mime type from file get contentcheck file mime type phpjavascript file size in mbphp function for file size 24filesize 3d 24 files 5b 27file 27 5d 5b 27size 27 5d 3b 24 file is of type in phphow to get file mime type in phpphp how to get file typefile mime type phpphp file get sizehow to get content or file mime type in phphow to get mime type using content in phphwo to get name and size of the file from form in phpshow size of a file phpphp file size 102400000get file size 5cphpget file type phphow to display file size in phpphp read file sizefile size in phpphp get file tiypehow to find out file type phptype file phpphp get file size in bytesphp get mime type from filenameget file size by path phpphp get file sizefrom requestphp get file type from stringhow to get content mime type using phpget file sixe in phpphp fileinfo mime typeget file type with phpphp file type getget php pathphp find files length zerophp check file mime type imagephp file size pdf stringcheck content file sizes too small phpphp size of filephp get file type from filephp get image mime typeget the file type in phphow to get file size dynaically in phpphp get file size bytesphp get files of typeget length of a file phpwhich attribute depicts the mime type of file in phpget mime type of file path phpfilesize based on pathupload file check size file in phpfiletype phphow to check mime type in phpget file extension phpfiletype in phphow to check the sizeof of file in phpphp zise filephp get file size inimime type srt file phphow to check the size of the file in phphow to determine file type phpcheck mime type from file tmp phpphp get file extension by mime typephp check file mime typephp check uploaded file mime type imagephp get mime type of a file without downloadget file content type phpgetfilesize phpphp filezisehow to get size file in phpsize file phpphp test file sizeget mime type from file name phpphp get file mime typephp get filetyepyeephp file get typecheck file mime type in phpphp get file image typephp set mime type of filephp get filetyepyeget file type in phpsize of file is given in in php 3fphp get file name size and typephp get file type from filenamesize of file phpphp get file size on dirphp file dimensionfiletype 3a 22php 22get size or file phpphp filesize functionget file mimetype phpphp get file size from urlcalulator file size phpphp max file sizeghow to get file size in phpfile type phpphp get file content mime typehow to get mime type of a content or a file in phpphp type filephp file mime type from file namejavascript iset max file sizehow to get mime type using file content in phpphp get file sizecalculator size of the uploaded file 2c in phpphp get extension from content typecalcute file size phpphp get mime type imagephp get filetyephp read file file size not match real filefind a files size phpphp get file mime from pathget the size of a file in phpcheck file size phphow to get file sizephp find files lengthget size of way file data phpphp get mime type from filephp check filetypeget file size 2b phpphp files size in mbyou need to check the size of a file in php function 24size 3d x 28filename 29 3b which function will suitably replace 27x 27 3fphp get mime type of uploaded filedisplay file size phpget mime types phpget total length of data in txt file phppathinfo 28 29 2b get file mime type 2b phpmime type file phpget all files size of file phpphp get size of a filecalculate file length phpphp get file mime content typehow to get file contents size from phpget the file size in phpget mime type from extension phpubuntu php write file get zero sizephp get mime type from contentphp how to check file sizephp get filetypeasize of a file phpget size of any file phpget url file size zero phpphp determine file typephp check file size 0filesize 28 29 phphphp file sizwedetermine file types in phpphp get mime type of file before uploadcheck file size php 7 4get file size of local file phpget file mime tyep phpcheck file type phplogging file size increase pythoncheck size of file phpphp get type of filephp get rid of file namephp file size for fread 28 29php get file size in kb from urlget mime of file phpphp find file sizephp get file size from 24 filehow to get size of file in phpphp get the type of filehow to get file size phpget file type of file phpphp how to upload 10mb txt to serverusing php to check file sizehwo to get name and size of the file in phpphp filesize 28 29find length of a text file in phpget mime type of file 2b phphow top know the file type in phpcheck mime type of file phphow to get file type name using phpis filesize a int phpphp filezieget input type file value in phpdetermine mime type of file phpunction is used to get the size of a file in phpphp mime type from filenamecheck for file size phpphp find file typephp file with image mime typemime type phppgp get file size in kbphp get size from file imagefile size phpphp get file size by urlhow to get the file type in phphow to get file stream mime type in phpphp get file mimetypefiletype 3a phpphp get input type filein php file size get mime type of file in phpphp upload get file sizephp file mime typehow to get correct file or content mime type using 2fin phpphp 24 file get typephp get size of filecheck file size in phpget mime type of file path in phpfilesize 28 29 typeget mime type using file name phpget mimetype of a file php php get file upload max sizephp command line file size limit command line getget mime type of file phphow to get mime type of file in phpuse mime to get file extension phpphp file length charget file size info phpphp file sizephp file size in mbfunction to get file type by mime phpphp get file mime type from fileget file length of uploaded phpphp ffile sizephp get filetyphp file mimeusing php to check file size and block certain sizesphp calculate file sizehwo to get name and size of the file from from in phpphp get post filesizephp check size filehow to get mime type using file name phpget file length from files phpphp fopen sizeget file sizeget mime type of uploaded file phppgp get file sizehow to get file type in phpphp get file size of uploaded filephp get file content typephp file size in bitsphp how to know readfile mime typeget type file php 24files is of type in phpget type of file phpfilesize in phpphp read file typesphp file sizefilesize phpusing file name get mime type in phpphp get size of uploaded filephp filesizephp filesize of pdf stringget file mime type 2b phpphp getfilesizeputting file type and file size in php file uploadphp get size of filereaderphp get file typecheck file size php file uploadmime type for php filephp get mime typeget filesizefiletype 28 29 phpget mime type of file in storage in phpphp get length of filefilesize path phpphp get filetyepyfile type in phpget file length phpget file type from file phpphp get content length of a filefilesizephp size documentfilesyze phpget size file phpphp file typefilesize url phpfiletype 3a phpphp filetypeget mime type file php postphp check a file 27s mime typecheck filetype phplimit the size of file in phphow many mb is 500000 in php image file sizefopen get file type phpfopne 0 byte file phpformat file size phpphp size filephp filetype 28 29how to determine file type in phpget the file size of archive in phphow can i know file size when upload file in phpcheck file size file size 2f 1024 2f 1024 3c 2 3bphp glob file size in mbfilesize 28filename 29 phpphp get file type formcheck mime of input uploaded phpphp calculate size of filephp get size of folderget file extension php mimetypephp get filetype from urlfinding size of file using phpphp print file sizephp check if file sizeget type of file with phpget size of file php wread file size php php check file sizeget mime type from file phpcontroller check file size in php codephp check file dimensionphp file upload mime typeget file size dynaically in phpphp check uploaded file sizephp filesize 28 24filename 29 to char numberphp get filesizephp check file size before deletephp get file type from contentget file size in phpget file length from file phpsize converter phpget file extension from mime type 2b phpfile length phpphp return typefileinfo mime type in phpphp get file extension from mime typefile file type phpyou need to check the size of a file in php functionget a file size in phppretty filesize phpget sizes of files in folder phpget file mime type phpget file size large file phpphp get file mime type