File.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. namespace Faker\Provider;
  3. class File extends Base
  4. {
  5. /**
  6. * MIME types from the apache.org file. Some types are truncated.
  7. *
  8. * @var array Map of MIME types => file extension(s)
  9. *
  10. * @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
  11. */
  12. protected static $mimeTypes = [
  13. 'application/atom+xml' => 'atom',
  14. 'application/ecmascript' => 'ecma',
  15. 'application/emma+xml' => 'emma',
  16. 'application/epub+zip' => 'epub',
  17. 'application/java-archive' => 'jar',
  18. 'application/java-vm' => 'class',
  19. 'application/javascript' => 'js',
  20. 'application/json' => 'json',
  21. 'application/jsonml+json' => 'jsonml',
  22. 'application/lost+xml' => 'lostxml',
  23. 'application/mathml+xml' => 'mathml',
  24. 'application/mets+xml' => 'mets',
  25. 'application/mods+xml' => 'mods',
  26. 'application/mp4' => 'mp4s',
  27. 'application/msword' => ['doc', 'dot'],
  28. 'application/octet-stream' => [
  29. 'bin',
  30. 'dms',
  31. 'lrf',
  32. 'mar',
  33. 'so',
  34. 'dist',
  35. 'distz',
  36. 'pkg',
  37. 'bpk',
  38. 'dump',
  39. 'elc',
  40. 'deploy',
  41. ],
  42. 'application/ogg' => 'ogx',
  43. 'application/omdoc+xml' => 'omdoc',
  44. 'application/pdf' => 'pdf',
  45. 'application/pgp-encrypted' => 'pgp',
  46. 'application/pgp-signature' => ['asc', 'sig'],
  47. 'application/pkix-pkipath' => 'pkipath',
  48. 'application/pkixcmp' => 'pki',
  49. 'application/pls+xml' => 'pls',
  50. 'application/postscript' => ['ai', 'eps', 'ps'],
  51. 'application/pskc+xml' => 'pskcxml',
  52. 'application/rdf+xml' => 'rdf',
  53. 'application/reginfo+xml' => 'rif',
  54. 'application/rss+xml' => 'rss',
  55. 'application/rtf' => 'rtf',
  56. 'application/sbml+xml' => 'sbml',
  57. 'application/vnd.adobe.air-application-installer-package+zip' => 'air',
  58. 'application/vnd.adobe.xdp+xml' => 'xdp',
  59. 'application/vnd.adobe.xfdf' => 'xfdf',
  60. 'application/vnd.ahead.space' => 'ahead',
  61. 'application/vnd.dart' => 'dart',
  62. 'application/vnd.data-vision.rdz' => 'rdz',
  63. 'application/vnd.dece.data' => ['uvf', 'uvvf', 'uvd', 'uvvd'],
  64. 'application/vnd.dece.ttml+xml' => ['uvt', 'uvvt'],
  65. 'application/vnd.dece.unspecified' => ['uvx', 'uvvx'],
  66. 'application/vnd.dece.zip' => ['uvz', 'uvvz'],
  67. 'application/vnd.denovo.fcselayout-link' => 'fe_launch',
  68. 'application/vnd.dna' => 'dna',
  69. 'application/vnd.dolby.mlp' => 'mlp',
  70. 'application/vnd.dpgraph' => 'dpg',
  71. 'application/vnd.dreamfactory' => 'dfac',
  72. 'application/vnd.ds-keypoint' => 'kpxx',
  73. 'application/vnd.dvb.ait' => 'ait',
  74. 'application/vnd.dvb.service' => 'svc',
  75. 'application/vnd.dynageo' => 'geo',
  76. 'application/vnd.ecowin.chart' => 'mag',
  77. 'application/vnd.enliven' => 'nml',
  78. 'application/vnd.epson.esf' => 'esf',
  79. 'application/vnd.epson.msf' => 'msf',
  80. 'application/vnd.epson.quickanime' => 'qam',
  81. 'application/vnd.epson.salt' => 'slt',
  82. 'application/vnd.epson.ssf' => 'ssf',
  83. 'application/vnd.ezpix-album' => 'ez2',
  84. 'application/vnd.ezpix-package' => 'ez3',
  85. 'application/vnd.fdf' => 'fdf',
  86. 'application/vnd.fdsn.mseed' => 'mseed',
  87. 'application/vnd.fdsn.seed' => ['seed', 'dataless'],
  88. 'application/vnd.flographit' => 'gph',
  89. 'application/vnd.fluxtime.clip' => 'ftc',
  90. 'application/vnd.hal+xml' => 'hal',
  91. 'application/vnd.hydrostatix.sof-data' => 'sfd-hdstx',
  92. 'application/vnd.ibm.minipay' => 'mpy',
  93. 'application/vnd.ibm.secure-container' => 'sc',
  94. 'application/vnd.iccprofile' => ['icc', 'icm'],
  95. 'application/vnd.igloader' => 'igl',
  96. 'application/vnd.immervision-ivp' => 'ivp',
  97. 'application/vnd.kde.karbon' => 'karbon',
  98. 'application/vnd.kde.kchart' => 'chrt',
  99. 'application/vnd.kde.kformula' => 'kfo',
  100. 'application/vnd.kde.kivio' => 'flw',
  101. 'application/vnd.kde.kontour' => 'kon',
  102. 'application/vnd.kde.kpresenter' => ['kpr', 'kpt'],
  103. 'application/vnd.kde.kspread' => 'ksp',
  104. 'application/vnd.kde.kword' => ['kwd', 'kwt'],
  105. 'application/vnd.kenameaapp' => 'htke',
  106. 'application/vnd.kidspiration' => 'kia',
  107. 'application/vnd.kinar' => ['kne', 'knp'],
  108. 'application/vnd.koan' => ['skp', 'skd', 'skt', 'skm'],
  109. 'application/vnd.kodak-descriptor' => 'sse',
  110. 'application/vnd.las.las+xml' => 'lasxml',
  111. 'application/vnd.llamagraphics.life-balance.desktop' => 'lbd',
  112. 'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe',
  113. 'application/vnd.lotus-1-2-3' => '123',
  114. 'application/vnd.lotus-approach' => 'apr',
  115. 'application/vnd.lotus-freelance' => 'pre',
  116. 'application/vnd.lotus-notes' => 'nsf',
  117. 'application/vnd.lotus-organizer' => 'org',
  118. 'application/vnd.lotus-screencam' => 'scm',
  119. 'application/vnd.mozilla.xul+xml' => 'xul',
  120. 'application/vnd.ms-artgalry' => 'cil',
  121. 'application/vnd.ms-cab-compressed' => 'cab',
  122. 'application/vnd.ms-excel' => [
  123. 'xls',
  124. 'xlm',
  125. 'xla',
  126. 'xlc',
  127. 'xlt',
  128. 'xlw',
  129. ],
  130. 'application/vnd.ms-excel.addin.macroenabled.12' => 'xlam',
  131. 'application/vnd.ms-excel.sheet.binary.macroenabled.12' => 'xlsb',
  132. 'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm',
  133. 'application/vnd.ms-excel.template.macroenabled.12' => 'xltm',
  134. 'application/vnd.ms-fontobject' => 'eot',
  135. 'application/vnd.ms-htmlhelp' => 'chm',
  136. 'application/vnd.ms-ims' => 'ims',
  137. 'application/vnd.ms-lrm' => 'lrm',
  138. 'application/vnd.ms-officetheme' => 'thmx',
  139. 'application/vnd.ms-pki.seccat' => 'cat',
  140. 'application/vnd.ms-pki.stl' => 'stl',
  141. 'application/vnd.ms-powerpoint' => ['ppt', 'pps', 'pot'],
  142. 'application/vnd.ms-powerpoint.addin.macroenabled.12' => 'ppam',
  143. 'application/vnd.ms-powerpoint.presentation.macroenabled.12' => 'pptm',
  144. 'application/vnd.ms-powerpoint.slide.macroenabled.12' => 'sldm',
  145. 'application/vnd.ms-powerpoint.slideshow.macroenabled.12' => 'ppsm',
  146. 'application/vnd.ms-powerpoint.template.macroenabled.12' => 'potm',
  147. 'application/vnd.ms-project' => ['mpp', 'mpt'],
  148. 'application/vnd.ms-word.document.macroenabled.12' => 'docm',
  149. 'application/vnd.ms-word.template.macroenabled.12' => 'dotm',
  150. 'application/vnd.ms-works' => ['wps', 'wks', 'wcm', 'wdb'],
  151. 'application/vnd.ms-wpl' => 'wpl',
  152. 'application/vnd.ms-xpsdocument' => 'xps',
  153. 'application/vnd.mseq' => 'mseq',
  154. 'application/vnd.musician' => 'mus',
  155. 'application/vnd.oasis.opendocument.chart' => 'odc',
  156. 'application/vnd.oasis.opendocument.chart-template' => 'otc',
  157. 'application/vnd.oasis.opendocument.database' => 'odb',
  158. 'application/vnd.oasis.opendocument.formula' => 'odf',
  159. 'application/vnd.oasis.opendocument.formula-template' => 'odft',
  160. 'application/vnd.oasis.opendocument.graphics' => 'odg',
  161. 'application/vnd.oasis.opendocument.graphics-template' => 'otg',
  162. 'application/vnd.oasis.opendocument.image' => 'odi',
  163. 'application/vnd.oasis.opendocument.image-template' => 'oti',
  164. 'application/vnd.oasis.opendocument.presentation' => 'odp',
  165. 'application/vnd.oasis.opendocument.presentation-template' => 'otp',
  166. 'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
  167. 'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots',
  168. 'application/vnd.oasis.opendocument.text' => 'odt',
  169. 'application/vnd.oasis.opendocument.text-master' => 'odm',
  170. 'application/vnd.oasis.opendocument.text-template' => 'ott',
  171. 'application/vnd.oasis.opendocument.text-web' => 'oth',
  172. 'application/vnd.olpc-sugar' => 'xo',
  173. 'application/vnd.oma.dd2+xml' => 'dd2',
  174. 'application/vnd.openofficeorg.extension' => 'oxt',
  175. 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
  176. 'application/vnd.openxmlformats-officedocument.presentationml.slide' => 'sldx',
  177. 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx',
  178. 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'potx',
  179. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
  180. 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'xltx',
  181. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
  182. 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx',
  183. 'application/vnd.pvi.ptid1' => 'ptid',
  184. 'application/vnd.quark.quarkxpress' => [
  185. 'qxd',
  186. 'qxt',
  187. 'qwd',
  188. 'qwt',
  189. 'qxl',
  190. 'qxb',
  191. ],
  192. 'application/vnd.realvnc.bed' => 'bed',
  193. 'application/vnd.recordare.musicxml' => 'mxl',
  194. 'application/vnd.recordare.musicxml+xml' => 'musicxml',
  195. 'application/vnd.rig.cryptonote' => 'cryptonote',
  196. 'application/vnd.rim.cod' => 'cod',
  197. 'application/vnd.rn-realmedia' => 'rm',
  198. 'application/vnd.rn-realmedia-vbr' => 'rmvb',
  199. 'application/vnd.route66.link66+xml' => 'link66',
  200. 'application/vnd.sailingtracker.track' => 'st',
  201. 'application/vnd.seemail' => 'see',
  202. 'application/vnd.sema' => 'sema',
  203. 'application/vnd.semd' => 'semd',
  204. 'application/vnd.semf' => 'semf',
  205. 'application/vnd.shana.informed.formdata' => 'ifm',
  206. 'application/vnd.shana.informed.formtemplate' => 'itp',
  207. 'application/vnd.shana.informed.interchange' => 'iif',
  208. 'application/vnd.shana.informed.package' => 'ipk',
  209. 'application/vnd.simtech-mindmapper' => ['twd', 'twds'],
  210. 'application/vnd.smaf' => 'mmf',
  211. 'application/vnd.stepmania.stepchart' => 'sm',
  212. 'application/vnd.sun.xml.calc' => 'sxc',
  213. 'application/vnd.sun.xml.calc.template' => 'stc',
  214. 'application/vnd.sun.xml.draw' => 'sxd',
  215. 'application/vnd.sun.xml.draw.template' => 'std',
  216. 'application/vnd.sun.xml.impress' => 'sxi',
  217. 'application/vnd.sun.xml.impress.template' => 'sti',
  218. 'application/vnd.sun.xml.math' => 'sxm',
  219. 'application/vnd.sun.xml.writer' => 'sxw',
  220. 'application/vnd.sun.xml.writer.global' => 'sxg',
  221. 'application/vnd.sun.xml.writer.template' => 'stw',
  222. 'application/vnd.sus-calendar' => ['sus', 'susp'],
  223. 'application/vnd.svd' => 'svd',
  224. 'application/vnd.symbian.install' => ['sis', 'sisx'],
  225. 'application/vnd.syncml+xml' => 'xsm',
  226. 'application/vnd.syncml.dm+wbxml' => 'bdm',
  227. 'application/vnd.syncml.dm+xml' => 'xdm',
  228. 'application/vnd.tao.intent-module-archive' => 'tao',
  229. 'application/vnd.tcpdump.pcap' => ['pcap', 'cap', 'dmp'],
  230. 'application/vnd.tmobile-livetv' => 'tmo',
  231. 'application/vnd.trid.tpt' => 'tpt',
  232. 'application/vnd.triscape.mxs' => 'mxs',
  233. 'application/vnd.trueapp' => 'tra',
  234. 'application/vnd.ufdl' => ['ufd', 'ufdl'],
  235. 'application/vnd.uiq.theme' => 'utz',
  236. 'application/vnd.umajin' => 'umj',
  237. 'application/vnd.unity' => 'unityweb',
  238. 'application/vnd.uoml+xml' => 'uoml',
  239. 'application/vnd.vcx' => 'vcx',
  240. 'application/vnd.visio' => ['vsd', 'vst', 'vss', 'vsw'],
  241. 'application/vnd.visionary' => 'vis',
  242. 'application/vnd.vsf' => 'vsf',
  243. 'application/vnd.wap.wbxml' => 'wbxml',
  244. 'application/vnd.wap.wmlc' => 'wmlc',
  245. 'application/vnd.wap.wmlscriptc' => 'wmlsc',
  246. 'application/vnd.webturbo' => 'wtb',
  247. 'application/vnd.wolfram.player' => 'nbp',
  248. 'application/vnd.wordperfect' => 'wpd',
  249. 'application/vnd.wqd' => 'wqd',
  250. 'application/vnd.wt.stf' => 'stf',
  251. 'application/vnd.xara' => 'xar',
  252. 'application/vnd.xfdl' => 'xfdl',
  253. 'application/voicexml+xml' => 'vxml',
  254. 'application/widget' => 'wgt',
  255. 'application/winhlp' => 'hlp',
  256. 'application/wsdl+xml' => 'wsdl',
  257. 'application/wspolicy+xml' => 'wspolicy',
  258. 'application/x-7z-compressed' => '7z',
  259. 'application/x-bittorrent' => 'torrent',
  260. 'application/x-blorb' => ['blb', 'blorb'],
  261. 'application/x-bzip' => 'bz',
  262. 'application/x-cdlink' => 'vcd',
  263. 'application/x-cfs-compressed' => 'cfs',
  264. 'application/x-chat' => 'chat',
  265. 'application/x-chess-pgn' => 'pgn',
  266. 'application/x-conference' => 'nsc',
  267. 'application/x-cpio' => 'cpio',
  268. 'application/x-csh' => 'csh',
  269. 'application/x-debian-package' => ['deb', 'udeb'],
  270. 'application/x-dgc-compressed' => 'dgc',
  271. 'application/x-director' => [
  272. 'dir',
  273. 'dcr',
  274. 'dxr',
  275. 'cst',
  276. 'cct',
  277. 'cxt',
  278. 'w3d',
  279. 'fgd',
  280. 'swa',
  281. ],
  282. 'application/x-font-ttf' => ['ttf', 'ttc'],
  283. 'application/x-font-type1' => ['pfa', 'pfb', 'pfm', 'afm'],
  284. 'application/x-font-woff' => 'woff',
  285. 'application/x-freearc' => 'arc',
  286. 'application/x-futuresplash' => 'spl',
  287. 'application/x-gca-compressed' => 'gca',
  288. 'application/x-glulx' => 'ulx',
  289. 'application/x-gnumeric' => 'gnumeric',
  290. 'application/x-gramps-xml' => 'gramps',
  291. 'application/x-gtar' => 'gtar',
  292. 'application/x-hdf' => 'hdf',
  293. 'application/x-install-instructions' => 'install',
  294. 'application/x-iso9660-image' => 'iso',
  295. 'application/x-java-jnlp-file' => 'jnlp',
  296. 'application/x-latex' => 'latex',
  297. 'application/x-lzh-compressed' => ['lzh', 'lha'],
  298. 'application/x-mie' => 'mie',
  299. 'application/x-mobipocket-ebook' => ['prc', 'mobi'],
  300. 'application/x-ms-application' => 'application',
  301. 'application/x-ms-shortcut' => 'lnk',
  302. 'application/x-ms-wmd' => 'wmd',
  303. 'application/x-ms-wmz' => 'wmz',
  304. 'application/x-ms-xbap' => 'xbap',
  305. 'application/x-msaccess' => 'mdb',
  306. 'application/x-msbinder' => 'obd',
  307. 'application/x-mscardfile' => 'crd',
  308. 'application/x-msclip' => 'clp',
  309. 'application/x-msdownload' => ['exe', 'dll', 'com', 'bat', 'msi'],
  310. 'application/x-msmediaview' => [
  311. 'mvb',
  312. 'm13',
  313. 'm14',
  314. ],
  315. 'application/x-msmetafile' => ['wmf', 'wmz', 'emf', 'emz'],
  316. 'application/x-rar-compressed' => 'rar',
  317. 'application/x-research-info-systems' => 'ris',
  318. 'application/x-sh' => 'sh',
  319. 'application/x-shar' => 'shar',
  320. 'application/x-shockwave-flash' => 'swf',
  321. 'application/x-silverlight-app' => 'xap',
  322. 'application/x-sql' => 'sql',
  323. 'application/x-stuffit' => 'sit',
  324. 'application/x-stuffitx' => 'sitx',
  325. 'application/x-subrip' => 'srt',
  326. 'application/x-sv4cpio' => 'sv4cpio',
  327. 'application/x-sv4crc' => 'sv4crc',
  328. 'application/x-t3vm-image' => 't3',
  329. 'application/x-tads' => 'gam',
  330. 'application/x-tar' => 'tar',
  331. 'application/x-tcl' => 'tcl',
  332. 'application/x-tex' => 'tex',
  333. 'application/x-tex-tfm' => 'tfm',
  334. 'application/x-texinfo' => ['texinfo', 'texi'],
  335. 'application/x-tgif' => 'obj',
  336. 'application/x-ustar' => 'ustar',
  337. 'application/x-wais-source' => 'src',
  338. 'application/x-x509-ca-cert' => ['der', 'crt'],
  339. 'application/x-xfig' => 'fig',
  340. 'application/x-xliff+xml' => 'xlf',
  341. 'application/x-xpinstall' => 'xpi',
  342. 'application/x-xz' => 'xz',
  343. 'application/x-zmachine' => 'z1',
  344. 'application/xaml+xml' => 'xaml',
  345. 'application/xcap-diff+xml' => 'xdf',
  346. 'application/xenc+xml' => 'xenc',
  347. 'application/xhtml+xml' => ['xhtml', 'xht'],
  348. 'application/xml' => ['xml', 'xsl'],
  349. 'application/xml-dtd' => 'dtd',
  350. 'application/xop+xml' => 'xop',
  351. 'application/xproc+xml' => 'xpl',
  352. 'application/xslt+xml' => 'xslt',
  353. 'application/xspf+xml' => 'xspf',
  354. 'application/xv+xml' => ['mxml', 'xhvml', 'xvml', 'xvm'],
  355. 'application/yang' => 'yang',
  356. 'application/yin+xml' => 'yin',
  357. 'application/zip' => 'zip',
  358. 'audio/adpcm' => 'adp',
  359. 'audio/basic' => ['au', 'snd'],
  360. 'audio/midi' => ['mid', 'midi', 'kar', 'rmi'],
  361. 'audio/mp4' => 'mp4a',
  362. 'audio/mpeg' => [
  363. 'mpga',
  364. 'mp2',
  365. 'mp2a',
  366. 'mp3',
  367. 'm2a',
  368. 'm3a',
  369. ],
  370. 'audio/ogg' => ['oga', 'ogg', 'spx'],
  371. 'audio/vnd.dece.audio' => ['uva', 'uvva'],
  372. 'audio/vnd.rip' => 'rip',
  373. 'audio/webm' => 'weba',
  374. 'audio/x-aac' => 'aac',
  375. 'audio/x-aiff' => ['aif', 'aiff', 'aifc'],
  376. 'audio/x-caf' => 'caf',
  377. 'audio/x-flac' => 'flac',
  378. 'audio/x-matroska' => 'mka',
  379. 'audio/x-mpegurl' => 'm3u',
  380. 'audio/x-ms-wax' => 'wax',
  381. 'audio/x-ms-wma' => 'wma',
  382. 'audio/x-pn-realaudio' => ['ram', 'ra'],
  383. 'audio/x-pn-realaudio-plugin' => 'rmp',
  384. 'audio/x-wav' => 'wav',
  385. 'audio/xm' => 'xm',
  386. 'image/bmp' => 'bmp',
  387. 'image/cgm' => 'cgm',
  388. 'image/g3fax' => 'g3',
  389. 'image/gif' => 'gif',
  390. 'image/ief' => 'ief',
  391. 'image/jpeg' => ['jpeg', 'jpg', 'jpe'],
  392. 'image/ktx' => 'ktx',
  393. 'image/png' => 'png',
  394. 'image/prs.btif' => 'btif',
  395. 'image/sgi' => 'sgi',
  396. 'image/svg+xml' => ['svg', 'svgz'],
  397. 'image/tiff' => ['tiff', 'tif'],
  398. 'image/vnd.adobe.photoshop' => 'psd',
  399. 'image/vnd.dece.graphic' => ['uvi', 'uvvi', 'uvg', 'uvvg'],
  400. 'image/vnd.dvb.subtitle' => 'sub',
  401. 'image/vnd.djvu' => ['djvu', 'djv'],
  402. 'image/vnd.dwg' => 'dwg',
  403. 'image/vnd.dxf' => 'dxf',
  404. 'image/vnd.fastbidsheet' => 'fbs',
  405. 'image/vnd.fpx' => 'fpx',
  406. 'image/vnd.fst' => 'fst',
  407. 'image/vnd.fujixerox.edmics-mmr' => 'mmr',
  408. 'image/vnd.fujixerox.edmics-rlc' => 'rlc',
  409. 'image/vnd.ms-modi' => 'mdi',
  410. 'image/vnd.ms-photo' => 'wdp',
  411. 'image/vnd.net-fpx' => 'npx',
  412. 'image/vnd.wap.wbmp' => 'wbmp',
  413. 'image/vnd.xiff' => 'xif',
  414. 'image/webp' => 'webp',
  415. 'image/x-3ds' => '3ds',
  416. 'image/x-cmu-raster' => 'ras',
  417. 'image/x-cmx' => 'cmx',
  418. 'image/x-freehand' => ['fh', 'fhc', 'fh4', 'fh5', 'fh7'],
  419. 'image/x-icon' => 'ico',
  420. 'image/x-mrsid-image' => 'sid',
  421. 'image/x-pcx' => 'pcx',
  422. 'image/x-pict' => ['pic', 'pct'],
  423. 'image/x-portable-anymap' => 'pnm',
  424. 'image/x-portable-bitmap' => 'pbm',
  425. 'image/x-portable-graymap' => 'pgm',
  426. 'image/x-portable-pixmap' => 'ppm',
  427. 'image/x-rgb' => 'rgb',
  428. 'image/x-tga' => 'tga',
  429. 'image/x-xbitmap' => 'xbm',
  430. 'image/x-xpixmap' => 'xpm',
  431. 'image/x-xwindowdump' => 'xwd',
  432. 'message/rfc822' => ['eml', 'mime'],
  433. 'model/iges' => ['igs', 'iges'],
  434. 'model/mesh' => ['msh', 'mesh', 'silo'],
  435. 'model/vnd.collada+xml' => 'dae',
  436. 'model/vnd.dwf' => 'dwf',
  437. 'model/vnd.gdl' => 'gdl',
  438. 'model/vnd.gtw' => 'gtw',
  439. 'model/vnd.mts' => 'mts',
  440. 'model/vnd.vtu' => 'vtu',
  441. 'model/vrml' => ['wrl', 'vrml'],
  442. 'model/x3d+binary' => 'x3db',
  443. 'model/x3d+vrml' => 'x3dv',
  444. 'model/x3d+xml' => 'x3d',
  445. 'text/cache-manifest' => 'appcache',
  446. 'text/calendar' => ['ics', 'ifb'],
  447. 'text/css' => 'css',
  448. 'text/csv' => 'csv',
  449. 'text/html' => ['html', 'htm'],
  450. 'text/n3' => 'n3',
  451. 'text/plain' => [
  452. 'txt',
  453. 'text',
  454. 'conf',
  455. 'def',
  456. 'list',
  457. 'log',
  458. 'in',
  459. ],
  460. 'text/prs.lines.tag' => 'dsc',
  461. 'text/richtext' => 'rtx',
  462. 'text/sgml' => ['sgml', 'sgm'],
  463. 'text/tab-separated-values' => 'tsv',
  464. 'text/troff' => [
  465. 't',
  466. 'tr',
  467. 'roff',
  468. 'man',
  469. 'me',
  470. 'ms',
  471. ],
  472. 'text/turtle' => 'ttl',
  473. 'text/uri-list' => ['uri', 'uris', 'urls'],
  474. 'text/vcard' => 'vcard',
  475. 'text/vnd.curl' => 'curl',
  476. 'text/vnd.curl.dcurl' => 'dcurl',
  477. 'text/vnd.curl.scurl' => 'scurl',
  478. 'text/vnd.curl.mcurl' => 'mcurl',
  479. 'text/vnd.dvb.subtitle' => 'sub',
  480. 'text/vnd.fly' => 'fly',
  481. 'text/vnd.fmi.flexstor' => 'flx',
  482. 'text/vnd.graphviz' => 'gv',
  483. 'text/vnd.in3d.3dml' => '3dml',
  484. 'text/vnd.in3d.spot' => 'spot',
  485. 'text/vnd.sun.j2me.app-descriptor' => 'jad',
  486. 'text/vnd.wap.wml' => 'wml',
  487. 'text/vnd.wap.wmlscript' => 'wmls',
  488. 'text/x-asm' => ['s', 'asm'],
  489. 'text/x-fortran' => ['f', 'for', 'f77', 'f90'],
  490. 'text/x-java-source' => 'java',
  491. 'text/x-opml' => 'opml',
  492. 'text/x-pascal' => ['p', 'pas'],
  493. 'text/x-nfo' => 'nfo',
  494. 'text/x-setext' => 'etx',
  495. 'text/x-sfv' => 'sfv',
  496. 'text/x-uuencode' => 'uu',
  497. 'text/x-vcalendar' => 'vcs',
  498. 'text/x-vcard' => 'vcf',
  499. 'video/3gpp' => '3gp',
  500. 'video/3gpp2' => '3g2',
  501. 'video/h261' => 'h261',
  502. 'video/h263' => 'h263',
  503. 'video/h264' => 'h264',
  504. 'video/jpeg' => 'jpgv',
  505. 'video/jpm' => ['jpm', 'jpgm'],
  506. 'video/mj2' => 'mj2',
  507. 'video/mp4' => 'mp4',
  508. 'video/mpeg' => ['mpeg', 'mpg', 'mpe', 'm1v', 'm2v'],
  509. 'video/ogg' => 'ogv',
  510. 'video/quicktime' => ['qt', 'mov'],
  511. 'video/vnd.dece.hd' => ['uvh', 'uvvh'],
  512. 'video/vnd.dece.mobile' => ['uvm', 'uvvm'],
  513. 'video/vnd.dece.pd' => ['uvp', 'uvvp'],
  514. 'video/vnd.dece.sd' => ['uvs', 'uvvs'],
  515. 'video/vnd.dece.video' => ['uvv', 'uvvv'],
  516. 'video/vnd.dvb.file' => 'dvb',
  517. 'video/vnd.fvt' => 'fvt',
  518. 'video/vnd.mpegurl' => ['mxu', 'm4u'],
  519. 'video/vnd.ms-playready.media.pyv' => 'pyv',
  520. 'video/vnd.uvvu.mp4' => ['uvu', 'uvvu'],
  521. 'video/vnd.vivo' => 'viv',
  522. 'video/webm' => 'webm',
  523. 'video/x-f4v' => 'f4v',
  524. 'video/x-fli' => 'fli',
  525. 'video/x-flv' => 'flv',
  526. 'video/x-m4v' => 'm4v',
  527. 'video/x-matroska' => ['mkv', 'mk3d', 'mks'],
  528. 'video/x-mng' => 'mng',
  529. 'video/x-ms-asf' => ['asf', 'asx'],
  530. 'video/x-ms-vob' => 'vob',
  531. 'video/x-ms-wm' => 'wm',
  532. 'video/x-ms-wmv' => 'wmv',
  533. 'video/x-ms-wmx' => 'wmx',
  534. 'video/x-ms-wvx' => 'wvx',
  535. 'video/x-msvideo' => 'avi',
  536. 'video/x-sgi-movie' => 'movie',
  537. ];
  538. /**
  539. * Get a random MIME type
  540. *
  541. * @return string
  542. *
  543. * @example 'video/avi'
  544. */
  545. public static function mimeType()
  546. {
  547. return static::randomElement(array_keys(static::$mimeTypes));
  548. }
  549. /**
  550. * Get a random file extension (without a dot)
  551. *
  552. * @example avi
  553. *
  554. * @return string
  555. */
  556. public static function fileExtension()
  557. {
  558. $random_extension = static::randomElement(array_values(static::$mimeTypes));
  559. return is_array($random_extension) ? static::randomElement($random_extension) : $random_extension;
  560. }
  561. /**
  562. * Copy a random file from the source directory to the target directory and returns the filename/fullpath
  563. *
  564. * @param string $sourceDirectory The directory to look for random file taking
  565. * @param string $targetDirectory
  566. * @param bool $fullPath Whether to have the full path or just the filename
  567. *
  568. * @return string
  569. */
  570. public static function file($sourceDirectory = '/tmp', $targetDirectory = '/tmp', $fullPath = true)
  571. {
  572. if (!is_dir($sourceDirectory)) {
  573. throw new \InvalidArgumentException(sprintf('Source directory %s does not exist or is not a directory.', $sourceDirectory));
  574. }
  575. if (!is_dir($targetDirectory)) {
  576. throw new \InvalidArgumentException(sprintf('Target directory %s does not exist or is not a directory.', $targetDirectory));
  577. }
  578. if ($sourceDirectory == $targetDirectory) {
  579. throw new \InvalidArgumentException('Source and target directories must differ.');
  580. }
  581. // Drop . and .. and reset array keys
  582. $files = array_filter(array_values(array_diff(scandir($sourceDirectory), ['.', '..'])), static function ($file) use ($sourceDirectory) {
  583. return is_file($sourceDirectory . DIRECTORY_SEPARATOR . $file) && is_readable($sourceDirectory . DIRECTORY_SEPARATOR . $file);
  584. });
  585. if (empty($files)) {
  586. throw new \InvalidArgumentException(sprintf('Source directory %s is empty.', $sourceDirectory));
  587. }
  588. $sourceFullPath = $sourceDirectory . DIRECTORY_SEPARATOR . static::randomElement($files);
  589. $destinationFile = Uuid::uuid() . '.' . pathinfo($sourceFullPath, PATHINFO_EXTENSION);
  590. $destinationFullPath = $targetDirectory . DIRECTORY_SEPARATOR . $destinationFile;
  591. if (false === copy($sourceFullPath, $destinationFullPath)) {
  592. return false;
  593. }
  594. return $fullPath ? $destinationFullPath : $destinationFile;
  595. }
  596. }