|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\HttpFoundation\File; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\HttpFoundation\File\Exception\FileException; |
|
|
15 |
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; |
|
|
16 |
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; |
|
|
17 |
|
|
|
18 |
/** |
|
|
19 |
* A file in the file system. |
|
|
20 |
* |
|
|
21 |
* @author Bernhard Schussek <bernhard.schussek@symfony.com> |
|
|
22 |
* |
|
|
23 |
* @api |
|
|
24 |
*/ |
|
|
25 |
class File extends \SplFileInfo |
|
|
26 |
{ |
|
|
27 |
/** |
|
|
28 |
* A map of mime types and their default extensions. |
|
|
29 |
* |
|
|
30 |
* @var array |
|
|
31 |
*/ |
|
|
32 |
static protected $defaultExtensions = array( |
|
|
33 |
'application/andrew-inset' => 'ez', |
|
|
34 |
'application/appledouble' => 'base64', |
|
|
35 |
'application/applefile' => 'base64', |
|
|
36 |
'application/commonground' => 'dp', |
|
|
37 |
'application/cprplayer' => 'pqi', |
|
|
38 |
'application/dsptype' => 'tsp', |
|
|
39 |
'application/excel' => 'xls', |
|
|
40 |
'application/font-tdpfr' => 'pfr', |
|
|
41 |
'application/futuresplash' => 'spl', |
|
|
42 |
'application/hstu' => 'stk', |
|
|
43 |
'application/hyperstudio' => 'stk', |
|
|
44 |
'application/javascript' => 'js', |
|
|
45 |
'application/mac-binhex40' => 'hqx', |
|
|
46 |
'application/mac-compactpro' => 'cpt', |
|
|
47 |
'application/mbed' => 'mbd', |
|
|
48 |
'application/mirage' => 'mfp', |
|
|
49 |
'application/msword' => 'doc', |
|
|
50 |
'application/ocsp-request' => 'orq', |
|
|
51 |
'application/ocsp-response' => 'ors', |
|
|
52 |
'application/octet-stream' => 'bin', |
|
|
53 |
'application/oda' => 'oda', |
|
|
54 |
'application/ogg' => 'ogg', |
|
|
55 |
'application/pdf' => 'pdf', |
|
|
56 |
'application/x-pdf' => 'pdf', |
|
|
57 |
'application/pgp-encrypted' => '7bit', |
|
|
58 |
'application/pgp-keys' => '7bit', |
|
|
59 |
'application/pgp-signature' => 'sig', |
|
|
60 |
'application/pkcs10' => 'p10', |
|
|
61 |
'application/pkcs7-mime' => 'p7m', |
|
|
62 |
'application/pkcs7-signature' => 'p7s', |
|
|
63 |
'application/pkix-cert' => 'cer', |
|
|
64 |
'application/pkix-crl' => 'crl', |
|
|
65 |
'application/pkix-pkipath' => 'pkipath', |
|
|
66 |
'application/pkixcmp' => 'pki', |
|
|
67 |
'application/postscript' => 'ps', |
|
|
68 |
'application/presentations' => 'shw', |
|
|
69 |
'application/prs.cww' => 'cw', |
|
|
70 |
'application/prs.nprend' => 'rnd', |
|
|
71 |
'application/quest' => 'qrt', |
|
|
72 |
'application/rtf' => 'rtf', |
|
|
73 |
'application/sgml-open-catalog' => 'soc', |
|
|
74 |
'application/sieve' => 'siv', |
|
|
75 |
'application/smil' => 'smi', |
|
|
76 |
'application/toolbook' => 'tbk', |
|
|
77 |
'application/vnd.3gpp.pic-bw-large' => 'plb', |
|
|
78 |
'application/vnd.3gpp.pic-bw-small' => 'psb', |
|
|
79 |
'application/vnd.3gpp.pic-bw-var' => 'pvb', |
|
|
80 |
'application/vnd.3gpp.sms' => 'sms', |
|
|
81 |
'application/vnd.acucorp' => 'atc', |
|
|
82 |
'application/vnd.adobe.xfdf' => 'xfdf', |
|
|
83 |
'application/vnd.amiga.amu' => 'ami', |
|
|
84 |
'application/vnd.blueice.multipass' => 'mpm', |
|
|
85 |
'application/vnd.cinderella' => 'cdy', |
|
|
86 |
'application/vnd.cosmocaller' => 'cmc', |
|
|
87 |
'application/vnd.criticaltools.wbs+xml' => 'wbs', |
|
|
88 |
'application/vnd.curl' => 'curl', |
|
|
89 |
'application/vnd.data-vision.rdz' => 'rdz', |
|
|
90 |
'application/vnd.dreamfactory' => 'dfac', |
|
|
91 |
'application/vnd.fsc.weblaunch' => 'fsc', |
|
|
92 |
'application/vnd.genomatix.tuxedo' => 'txd', |
|
|
93 |
'application/vnd.hbci' => 'hbci', |
|
|
94 |
'application/vnd.hhe.lesson-player' => 'les', |
|
|
95 |
'application/vnd.hp-hpgl' => 'plt', |
|
|
96 |
'application/vnd.ibm.electronic-media' => 'emm', |
|
|
97 |
'application/vnd.ibm.rights-management' => 'irm', |
|
|
98 |
'application/vnd.ibm.secure-container' => 'sc', |
|
|
99 |
'application/vnd.ipunplugged.rcprofile' => 'rcprofile', |
|
|
100 |
'application/vnd.irepository.package+xml' => 'irp', |
|
|
101 |
'application/vnd.jisp' => 'jisp', |
|
|
102 |
'application/vnd.kde.karbon' => 'karbon', |
|
|
103 |
'application/vnd.kde.kchart' => 'chrt', |
|
|
104 |
'application/vnd.kde.kformula' => 'kfo', |
|
|
105 |
'application/vnd.kde.kivio' => 'flw', |
|
|
106 |
'application/vnd.kde.kontour' => 'kon', |
|
|
107 |
'application/vnd.kde.kpresenter' => 'kpr', |
|
|
108 |
'application/vnd.kde.kspread' => 'ksp', |
|
|
109 |
'application/vnd.kde.kword' => 'kwd', |
|
|
110 |
'application/vnd.kenameapp' => 'htke', |
|
|
111 |
'application/vnd.kidspiration' => 'kia', |
|
|
112 |
'application/vnd.kinar' => 'kne', |
|
|
113 |
'application/vnd.llamagraphics.life-balance.desktop' => 'lbd', |
|
|
114 |
'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe', |
|
|
115 |
'application/vnd.lotus-1-2-3' => 'wks', |
|
|
116 |
'application/vnd.mcd' => 'mcd', |
|
|
117 |
'application/vnd.mfmp' => 'mfm', |
|
|
118 |
'application/vnd.micrografx.flo' => 'flo', |
|
|
119 |
'application/vnd.micrografx.igx' => 'igx', |
|
|
120 |
'application/vnd.mif' => 'mif', |
|
|
121 |
'application/vnd.mophun.application' => 'mpn', |
|
|
122 |
'application/vnd.mophun.certificate' => 'mpc', |
|
|
123 |
'application/vnd.mozilla.xul+xml' => 'xul', |
|
|
124 |
'application/vnd.ms-artgalry' => 'cil', |
|
|
125 |
'application/vnd.ms-asf' => 'asf', |
|
|
126 |
'application/vnd.ms-excel' => 'xls', |
|
|
127 |
'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm', |
|
|
128 |
'application/vnd.ms-lrm' => 'lrm', |
|
|
129 |
'application/vnd.ms-powerpoint' => 'ppt', |
|
|
130 |
'application/vnd.ms-project' => 'mpp', |
|
|
131 |
'application/vnd.ms-tnef' => 'base64', |
|
|
132 |
'application/vnd.ms-works' => 'base64', |
|
|
133 |
'application/vnd.ms-wpl' => 'wpl', |
|
|
134 |
'application/vnd.mseq' => 'mseq', |
|
|
135 |
'application/vnd.nervana' => 'ent', |
|
|
136 |
'application/vnd.nokia.radio-preset' => 'rpst', |
|
|
137 |
'application/vnd.nokia.radio-presets' => 'rpss', |
|
|
138 |
'application/vnd.oasis.opendocument.text' => 'odt', |
|
|
139 |
'application/vnd.oasis.opendocument.text-template' => 'ott', |
|
|
140 |
'application/vnd.oasis.opendocument.text-web' => 'oth', |
|
|
141 |
'application/vnd.oasis.opendocument.text-master' => 'odm', |
|
|
142 |
'application/vnd.oasis.opendocument.graphics' => 'odg', |
|
|
143 |
'application/vnd.oasis.opendocument.graphics-template' => 'otg', |
|
|
144 |
'application/vnd.oasis.opendocument.presentation' => 'odp', |
|
|
145 |
'application/vnd.oasis.opendocument.presentation-template' => 'otp', |
|
|
146 |
'application/vnd.oasis.opendocument.spreadsheet' => 'ods', |
|
|
147 |
'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots', |
|
|
148 |
'application/vnd.oasis.opendocument.chart' => 'odc', |
|
|
149 |
'application/vnd.oasis.opendocument.formula' => 'odf', |
|
|
150 |
'application/vnd.oasis.opendocument.database' => 'odb', |
|
|
151 |
'application/vnd.oasis.opendocument.image' => 'odi', |
|
|
152 |
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', |
|
|
153 |
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx', |
|
|
154 |
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', |
|
|
155 |
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', |
|
|
156 |
'application/vnd.palm' => 'prc', |
|
|
157 |
'application/vnd.picsel' => 'efif', |
|
|
158 |
'application/vnd.pvi.ptid1' => 'pti', |
|
|
159 |
'application/vnd.quark.quarkxpress' => 'qxd', |
|
|
160 |
'application/vnd.sealed.doc' => 'sdoc', |
|
|
161 |
'application/vnd.sealed.eml' => 'seml', |
|
|
162 |
'application/vnd.sealed.mht' => 'smht', |
|
|
163 |
'application/vnd.sealed.ppt' => 'sppt', |
|
|
164 |
'application/vnd.sealed.xls' => 'sxls', |
|
|
165 |
'application/vnd.sealedmedia.softseal.html' => 'stml', |
|
|
166 |
'application/vnd.sealedmedia.softseal.pdf' => 'spdf', |
|
|
167 |
'application/vnd.seemail' => 'see', |
|
|
168 |
'application/vnd.smaf' => 'mmf', |
|
|
169 |
'application/vnd.sun.xml.calc' => 'sxc', |
|
|
170 |
'application/vnd.sun.xml.calc.template' => 'stc', |
|
|
171 |
'application/vnd.sun.xml.draw' => 'sxd', |
|
|
172 |
'application/vnd.sun.xml.draw.template' => 'std', |
|
|
173 |
'application/vnd.sun.xml.impress' => 'sxi', |
|
|
174 |
'application/vnd.sun.xml.impress.template' => 'sti', |
|
|
175 |
'application/vnd.sun.xml.math' => 'sxm', |
|
|
176 |
'application/vnd.sun.xml.writer' => 'sxw', |
|
|
177 |
'application/vnd.sun.xml.writer.global' => 'sxg', |
|
|
178 |
'application/vnd.sun.xml.writer.template' => 'stw', |
|
|
179 |
'application/vnd.sus-calendar' => 'sus', |
|
|
180 |
'application/vnd.vidsoft.vidconference' => 'vsc', |
|
|
181 |
'application/vnd.visio' => 'vsd', |
|
|
182 |
'application/vnd.visionary' => 'vis', |
|
|
183 |
'application/vnd.wap.sic' => 'sic', |
|
|
184 |
'application/vnd.wap.slc' => 'slc', |
|
|
185 |
'application/vnd.wap.wbxml' => 'wbxml', |
|
|
186 |
'application/vnd.wap.wmlc' => 'wmlc', |
|
|
187 |
'application/vnd.wap.wmlscriptc' => 'wmlsc', |
|
|
188 |
'application/vnd.webturbo' => 'wtb', |
|
|
189 |
'application/vnd.wordperfect' => 'wpd', |
|
|
190 |
'application/vnd.wqd' => 'wqd', |
|
|
191 |
'application/vnd.wv.csp+wbxml' => 'wv', |
|
|
192 |
'application/vnd.wv.csp+xml' => '8bit', |
|
|
193 |
'application/vnd.wv.ssp+xml' => '8bit', |
|
|
194 |
'application/vnd.yamaha.hv-dic' => 'hvd', |
|
|
195 |
'application/vnd.yamaha.hv-script' => 'hvs', |
|
|
196 |
'application/vnd.yamaha.hv-voice' => 'hvp', |
|
|
197 |
'application/vnd.yamaha.smaf-audio' => 'saf', |
|
|
198 |
'application/vnd.yamaha.smaf-phrase' => 'spf', |
|
|
199 |
'application/vocaltec-media-desc' => 'vmd', |
|
|
200 |
'application/vocaltec-media-file' => 'vmf', |
|
|
201 |
'application/vocaltec-talker' => 'vtk', |
|
|
202 |
'application/watcherinfo+xml' => 'wif', |
|
|
203 |
'application/wordperfect5.1' => 'wp5', |
|
|
204 |
'application/x-123' => 'wk', |
|
|
205 |
'application/x-7th_level_event' => '7ls', |
|
|
206 |
'application/x-authorware-bin' => 'aab', |
|
|
207 |
'application/x-authorware-map' => 'aam', |
|
|
208 |
'application/x-authorware-seg' => 'aas', |
|
|
209 |
'application/x-bcpio' => 'bcpio', |
|
|
210 |
'application/x-bleeper' => 'bleep', |
|
|
211 |
'application/x-bzip2' => 'bz2', |
|
|
212 |
'application/x-cdlink' => 'vcd', |
|
|
213 |
'application/x-chat' => 'chat', |
|
|
214 |
'application/x-chess-pgn' => 'pgn', |
|
|
215 |
'application/x-compress' => 'z', |
|
|
216 |
'application/x-cpio' => 'cpio', |
|
|
217 |
'application/x-cprplayer' => 'pqf', |
|
|
218 |
'application/x-csh' => 'csh', |
|
|
219 |
'application/x-cu-seeme' => 'csm', |
|
|
220 |
'application/x-cult3d-object' => 'co', |
|
|
221 |
'application/x-debian-package' => 'deb', |
|
|
222 |
'application/x-director' => 'dcr', |
|
|
223 |
'application/x-dvi' => 'dvi', |
|
|
224 |
'application/x-envoy' => 'evy', |
|
|
225 |
'application/x-futuresplash' => 'spl', |
|
|
226 |
'application/x-gtar' => 'gtar', |
|
|
227 |
'application/x-gzip' => 'gz', |
|
|
228 |
'application/x-hdf' => 'hdf', |
|
|
229 |
'application/x-hep' => 'hep', |
|
|
230 |
'application/x-html+ruby' => 'rhtml', |
|
|
231 |
'application/x-httpd-miva' => 'mv', |
|
|
232 |
'application/x-httpd-php' => 'phtml', |
|
|
233 |
'application/x-ica' => 'ica', |
|
|
234 |
'application/x-imagemap' => 'imagemap', |
|
|
235 |
'application/x-ipix' => 'ipx', |
|
|
236 |
'application/x-ipscript' => 'ips', |
|
|
237 |
'application/x-java-archive' => 'jar', |
|
|
238 |
'application/x-java-jnlp-file' => 'jnlp', |
|
|
239 |
'application/x-java-serialized-object' => 'ser', |
|
|
240 |
'application/x-java-vm' => 'class', |
|
|
241 |
'application/x-javascript' => 'js', |
|
|
242 |
'application/x-koan' => 'skp', |
|
|
243 |
'application/x-latex' => 'latex', |
|
|
244 |
'application/x-mac-compactpro' => 'cpt', |
|
|
245 |
'application/x-maker' => 'frm', |
|
|
246 |
'application/x-mathcad' => 'mcd', |
|
|
247 |
'application/x-midi' => 'mid', |
|
|
248 |
'application/x-mif' => 'mif', |
|
|
249 |
'application/x-msaccess' => 'mda', |
|
|
250 |
'application/x-msdos-program' => 'com', |
|
|
251 |
'application/x-msdownload' => 'base64', |
|
|
252 |
'application/x-msexcel' => 'xls', |
|
|
253 |
'application/x-msword' => 'doc', |
|
|
254 |
'application/x-netcdf' => 'nc', |
|
|
255 |
'application/x-ns-proxy-autoconfig' => 'pac', |
|
|
256 |
'application/x-pagemaker' => 'pm5', |
|
|
257 |
'application/x-perl' => 'pl', |
|
|
258 |
'application/x-pn-realmedia' => 'rp', |
|
|
259 |
'application/x-python' => 'py', |
|
|
260 |
'application/x-quicktimeplayer' => 'qtl', |
|
|
261 |
'application/x-rar-compressed' => 'rar', |
|
|
262 |
'application/x-ruby' => 'rb', |
|
|
263 |
'application/x-sh' => 'sh', |
|
|
264 |
'application/x-shar' => 'shar', |
|
|
265 |
'application/x-shockwave-flash' => 'swf', |
|
|
266 |
'application/x-sprite' => 'spr', |
|
|
267 |
'application/x-spss' => 'sav', |
|
|
268 |
'application/x-spt' => 'spt', |
|
|
269 |
'application/x-stuffit' => 'sit', |
|
|
270 |
'application/x-sv4cpio' => 'sv4cpio', |
|
|
271 |
'application/x-sv4crc' => 'sv4crc', |
|
|
272 |
'application/x-tar' => 'tar', |
|
|
273 |
'application/x-tcl' => 'tcl', |
|
|
274 |
'application/x-tex' => 'tex', |
|
|
275 |
'application/x-texinfo' => 'texinfo', |
|
|
276 |
'application/x-troff' => 't', |
|
|
277 |
'application/x-troff-man' => 'man', |
|
|
278 |
'application/x-troff-me' => 'me', |
|
|
279 |
'application/x-troff-ms' => 'ms', |
|
|
280 |
'application/x-twinvq' => 'vqf', |
|
|
281 |
'application/x-twinvq-plugin' => 'vqe', |
|
|
282 |
'application/x-ustar' => 'ustar', |
|
|
283 |
'application/x-vmsbackup' => 'bck', |
|
|
284 |
'application/x-wais-source' => 'src', |
|
|
285 |
'application/x-wingz' => 'wz', |
|
|
286 |
'application/x-word' => 'base64', |
|
|
287 |
'application/x-wordperfect6.1' => 'wp6', |
|
|
288 |
'application/x-x509-ca-cert' => 'crt', |
|
|
289 |
'application/x-zip-compressed' => 'zip', |
|
|
290 |
'application/xhtml+xml' => 'xhtml', |
|
|
291 |
'application/zip' => 'zip', |
|
|
292 |
'audio/3gpp' => '3gpp', |
|
|
293 |
'audio/amr' => 'amr', |
|
|
294 |
'audio/amr-wb' => 'awb', |
|
|
295 |
'audio/basic' => 'au', |
|
|
296 |
'audio/evrc' => 'evc', |
|
|
297 |
'audio/l16' => 'l16', |
|
|
298 |
'audio/midi' => 'mid', |
|
|
299 |
'audio/mpeg' => 'mp3', |
|
|
300 |
'audio/prs.sid' => 'sid', |
|
|
301 |
'audio/qcelp' => 'qcp', |
|
|
302 |
'audio/smv' => 'smv', |
|
|
303 |
'audio/vnd.audiokoz' => 'koz', |
|
|
304 |
'audio/vnd.digital-winds' => 'eol', |
|
|
305 |
'audio/vnd.everad.plj' => 'plj', |
|
|
306 |
'audio/vnd.lucent.voice' => 'lvp', |
|
|
307 |
'audio/vnd.nokia.mobile-xmf' => 'mxmf', |
|
|
308 |
'audio/vnd.nortel.vbk' => 'vbk', |
|
|
309 |
'audio/vnd.nuera.ecelp4800' => 'ecelp4800', |
|
|
310 |
'audio/vnd.nuera.ecelp7470' => 'ecelp7470', |
|
|
311 |
'audio/vnd.nuera.ecelp9600' => 'ecelp9600', |
|
|
312 |
'audio/vnd.sealedmedia.softseal.mpeg' => 'smp3', |
|
|
313 |
'audio/voxware' => 'vox', |
|
|
314 |
'audio/x-aiff' => 'aif', |
|
|
315 |
'audio/x-mid' => 'mid', |
|
|
316 |
'audio/x-midi' => 'mid', |
|
|
317 |
'audio/x-mpeg' => 'mp2', |
|
|
318 |
'audio/x-mpegurl' => 'mpu', |
|
|
319 |
'audio/x-pn-realaudio' => 'rm', |
|
|
320 |
'audio/x-pn-realaudio-plugin' => 'rpm', |
|
|
321 |
'audio/x-realaudio' => 'ra', |
|
|
322 |
'audio/x-wav' => 'wav', |
|
|
323 |
'chemical/x-csml' => 'csm', |
|
|
324 |
'chemical/x-embl-dl-nucleotide' => 'emb', |
|
|
325 |
'chemical/x-gaussian-cube' => 'cube', |
|
|
326 |
'chemical/x-gaussian-input' => 'gau', |
|
|
327 |
'chemical/x-jcamp-dx' => 'jdx', |
|
|
328 |
'chemical/x-mdl-molfile' => 'mol', |
|
|
329 |
'chemical/x-mdl-rxnfile' => 'rxn', |
|
|
330 |
'chemical/x-mdl-tgf' => 'tgf', |
|
|
331 |
'chemical/x-mopac-input' => 'mop', |
|
|
332 |
'chemical/x-pdb' => 'pdb', |
|
|
333 |
'chemical/x-rasmol' => 'scr', |
|
|
334 |
'chemical/x-xyz' => 'xyz', |
|
|
335 |
'drawing/dwf' => 'dwf', |
|
|
336 |
'drawing/x-dwf' => 'dwf', |
|
|
337 |
'i-world/i-vrml' => 'ivr', |
|
|
338 |
'image/bmp' => 'bmp', |
|
|
339 |
'image/cewavelet' => 'wif', |
|
|
340 |
'image/cis-cod' => 'cod', |
|
|
341 |
'image/fif' => 'fif', |
|
|
342 |
'image/gif' => 'gif', |
|
|
343 |
'image/ief' => 'ief', |
|
|
344 |
'image/jp2' => 'jp2', |
|
|
345 |
'image/jpeg' => 'jpg', |
|
|
346 |
'image/jpm' => 'jpm', |
|
|
347 |
'image/jpx' => 'jpf', |
|
|
348 |
'image/pict' => 'pic', |
|
|
349 |
'image/pjpeg' => 'jpg', |
|
|
350 |
'image/png' => 'png', |
|
|
351 |
'image/targa' => 'tga', |
|
|
352 |
'image/tiff' => 'tif', |
|
|
353 |
'image/vn-svf' => 'svf', |
|
|
354 |
'image/vnd.dgn' => 'dgn', |
|
|
355 |
'image/vnd.djvu' => 'djvu', |
|
|
356 |
'image/vnd.dwg' => 'dwg', |
|
|
357 |
'image/vnd.glocalgraphics.pgb' => 'pgb', |
|
|
358 |
'image/vnd.microsoft.icon' => 'ico', |
|
|
359 |
'image/vnd.ms-modi' => 'mdi', |
|
|
360 |
'image/vnd.sealed.png' => 'spng', |
|
|
361 |
'image/vnd.sealedmedia.softseal.gif' => 'sgif', |
|
|
362 |
'image/vnd.sealedmedia.softseal.jpg' => 'sjpg', |
|
|
363 |
'image/vnd.wap.wbmp' => 'wbmp', |
|
|
364 |
'image/x-bmp' => 'bmp', |
|
|
365 |
'image/x-cmu-raster' => 'ras', |
|
|
366 |
'image/x-freehand' => 'fh4', |
|
|
367 |
'image/x-png' => 'png', |
|
|
368 |
'image/x-portable-anymap' => 'pnm', |
|
|
369 |
'image/x-portable-bitmap' => 'pbm', |
|
|
370 |
'image/x-portable-graymap' => 'pgm', |
|
|
371 |
'image/x-portable-pixmap' => 'ppm', |
|
|
372 |
'image/x-rgb' => 'rgb', |
|
|
373 |
'image/x-xbitmap' => 'xbm', |
|
|
374 |
'image/x-xpixmap' => 'xpm', |
|
|
375 |
'image/x-xwindowdump' => 'xwd', |
|
|
376 |
'message/external-body' => '8bit', |
|
|
377 |
'message/news' => '8bit', |
|
|
378 |
'message/partial' => '8bit', |
|
|
379 |
'message/rfc822' => '8bit', |
|
|
380 |
'model/iges' => 'igs', |
|
|
381 |
'model/mesh' => 'msh', |
|
|
382 |
'model/vnd.parasolid.transmit.binary' => 'x_b', |
|
|
383 |
'model/vnd.parasolid.transmit.text' => 'x_t', |
|
|
384 |
'model/vrml' => 'wrl', |
|
|
385 |
'multipart/alternative' => '8bit', |
|
|
386 |
'multipart/appledouble' => '8bit', |
|
|
387 |
'multipart/digest' => '8bit', |
|
|
388 |
'multipart/mixed' => '8bit', |
|
|
389 |
'multipart/parallel' => '8bit', |
|
|
390 |
'text/comma-separated-values' => 'csv', |
|
|
391 |
'text/css' => 'css', |
|
|
392 |
'text/html' => 'html', |
|
|
393 |
'text/plain' => 'txt', |
|
|
394 |
'text/prs.fallenstein.rst' => 'rst', |
|
|
395 |
'text/richtext' => 'rtx', |
|
|
396 |
'text/rtf' => 'rtf', |
|
|
397 |
'text/sgml' => 'sgml', |
|
|
398 |
'text/tab-separated-values' => 'tsv', |
|
|
399 |
'text/vnd.net2phone.commcenter.command' => 'ccc', |
|
|
400 |
'text/vnd.sun.j2me.app-descriptor' => 'jad', |
|
|
401 |
'text/vnd.wap.si' => 'si', |
|
|
402 |
'text/vnd.wap.sl' => 'sl', |
|
|
403 |
'text/vnd.wap.wml' => 'wml', |
|
|
404 |
'text/vnd.wap.wmlscript' => 'wmls', |
|
|
405 |
'text/x-hdml' => 'hdml', |
|
|
406 |
'text/x-setext' => 'etx', |
|
|
407 |
'text/x-sgml' => 'sgml', |
|
|
408 |
'text/x-speech' => 'talk', |
|
|
409 |
'text/x-vcalendar' => 'vcs', |
|
|
410 |
'text/x-vcard' => 'vcf', |
|
|
411 |
'text/xml' => 'xml', |
|
|
412 |
'ulead/vrml' => 'uvr', |
|
|
413 |
'video/3gpp' => '3gp', |
|
|
414 |
'video/dl' => 'dl', |
|
|
415 |
'video/gl' => 'gl', |
|
|
416 |
'video/mj2' => 'mj2', |
|
|
417 |
'video/mpeg' => 'mpeg', |
|
|
418 |
'video/quicktime' => 'mov', |
|
|
419 |
'video/vdo' => 'vdo', |
|
|
420 |
'video/vivo' => 'viv', |
|
|
421 |
'video/vnd.fvt' => 'fvt', |
|
|
422 |
'video/vnd.mpegurl' => 'mxu', |
|
|
423 |
'video/vnd.nokia.interleaved-multimedia' => 'nim', |
|
|
424 |
'video/vnd.objectvideo' => 'mp4', |
|
|
425 |
'video/vnd.sealed.mpeg1' => 's11', |
|
|
426 |
'video/vnd.sealed.mpeg4' => 'smpg', |
|
|
427 |
'video/vnd.sealed.swf' => 'sswf', |
|
|
428 |
'video/vnd.sealedmedia.softseal.mov' => 'smov', |
|
|
429 |
'video/vnd.vivo' => 'vivo', |
|
|
430 |
'video/x-fli' => 'fli', |
|
|
431 |
'video/x-ms-asf' => 'asf', |
|
|
432 |
'video/x-ms-wmv' => 'wmv', |
|
|
433 |
'video/x-msvideo' => 'avi', |
|
|
434 |
'video/x-sgi-movie' => 'movie', |
|
|
435 |
'x-chemical/x-pdb' => 'pdb', |
|
|
436 |
'x-chemical/x-xyz' => 'xyz', |
|
|
437 |
'x-conference/x-cooltalk' => 'ice', |
|
|
438 |
'x-drawing/dwf' => 'dwf', |
|
|
439 |
'x-world/x-d96' => 'd', |
|
|
440 |
'x-world/x-svr' => 'svr', |
|
|
441 |
'x-world/x-vream' => 'vrw', |
|
|
442 |
'x-world/x-vrml' => 'wrl', |
|
|
443 |
); |
|
|
444 |
|
|
|
445 |
/** |
|
|
446 |
* Constructs a new file from the given path. |
|
|
447 |
* |
|
|
448 |
* @param string $path The path to the file |
|
|
449 |
* |
|
|
450 |
* @throws FileNotFoundException If the given path is not a file |
|
|
451 |
* |
|
|
452 |
* @api |
|
|
453 |
*/ |
|
|
454 |
public function __construct($path) |
|
|
455 |
{ |
|
|
456 |
if (!is_file($path)) { |
|
|
457 |
throw new FileNotFoundException($path); |
|
|
458 |
} |
|
|
459 |
|
|
|
460 |
parent::__construct($path); |
|
|
461 |
} |
|
|
462 |
|
|
|
463 |
/** |
|
|
464 |
* Returns the extension based on the mime type. |
|
|
465 |
* |
|
|
466 |
* If the mime type is unknown, returns null. |
|
|
467 |
* |
|
|
468 |
* @return string|null The guessed extension or null if it cannot be guessed |
|
|
469 |
* |
|
|
470 |
* @api |
|
|
471 |
*/ |
|
|
472 |
public function guessExtension() |
|
|
473 |
{ |
|
|
474 |
$type = $this->getMimeType(); |
|
|
475 |
|
|
|
476 |
return isset(static::$defaultExtensions[$type]) ? static::$defaultExtensions[$type] : null; |
|
|
477 |
} |
|
|
478 |
|
|
|
479 |
/** |
|
|
480 |
* Returns the mime type of the file. |
|
|
481 |
* |
|
|
482 |
* The mime type is guessed using the functions finfo(), mime_content_type() |
|
|
483 |
* and the system binary "file" (in this order), depending on which of those |
|
|
484 |
* is available on the current operating system. |
|
|
485 |
* |
|
|
486 |
* @return string|null The guessed mime type (i.e. "application/pdf") |
|
|
487 |
* |
|
|
488 |
* @api |
|
|
489 |
*/ |
|
|
490 |
public function getMimeType() |
|
|
491 |
{ |
|
|
492 |
$guesser = MimeTypeGuesser::getInstance(); |
|
|
493 |
|
|
|
494 |
return $guesser->guess($this->getPathname()); |
|
|
495 |
} |
|
|
496 |
|
|
|
497 |
/** |
|
|
498 |
* Returns the extension of the file. |
|
|
499 |
* |
|
|
500 |
* \SplFileInfo::getExtension() is not available before PHP 5.3.6 |
|
|
501 |
* |
|
|
502 |
* @return string The extension |
|
|
503 |
* |
|
|
504 |
* @api |
|
|
505 |
*/ |
|
|
506 |
public function getExtension() |
|
|
507 |
{ |
|
|
508 |
return pathinfo($this->getBasename(), PATHINFO_EXTENSION); |
|
|
509 |
} |
|
|
510 |
|
|
|
511 |
/** |
|
|
512 |
* Moves the file to a new location. |
|
|
513 |
* |
|
|
514 |
* @param string $directory The destination folder |
|
|
515 |
* @param string $name The new file name |
|
|
516 |
* |
|
|
517 |
* @return File A File object representing the new file |
|
|
518 |
* |
|
|
519 |
* @throws FileException if the target file could not be created |
|
|
520 |
* |
|
|
521 |
* @api |
|
|
522 |
*/ |
|
|
523 |
public function move($directory, $name = null) |
|
|
524 |
{ |
|
|
525 |
if (!is_dir($directory)) { |
|
|
526 |
if (false === @mkdir($directory, 0777, true)) { |
|
|
527 |
throw new FileException(sprintf('Unable to create the "%s" directory', $directory)); |
|
|
528 |
} |
|
|
529 |
} elseif (!is_writable($directory)) { |
|
|
530 |
throw new FileException(sprintf('Unable to write in the "%s" directory', $directory)); |
|
|
531 |
} |
|
|
532 |
|
|
|
533 |
$target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : basename($name)); |
|
|
534 |
|
|
|
535 |
if (!@rename($this->getPathname(), $target)) { |
|
|
536 |
$error = error_get_last(); |
|
|
537 |
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message']))); |
|
|
538 |
} |
|
|
539 |
|
|
|
540 |
chmod($target, 0666); |
|
|
541 |
|
|
|
542 |
return new File($target); |
|
|
543 |
} |
|
|
544 |
} |