mediafile.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <?php
  2. /**
  3. * GNU social - a federating social network
  4. *
  5. * Abstraction for media files
  6. *
  7. * LICENCE: This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @category Media
  21. * @package GNUsocial
  22. * @author Robin Millette <robin@millette.info>
  23. * @author Miguel Dantas <biodantas@gmail.com>
  24. * @author Zach Copley <zach@status.net>
  25. * @author Mikael Nordfeldth <mmn@hethane.se>
  26. * @copyright 2008-2009, 2019 Free Software Foundation http://fsf.org
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link https://www.gnu.org/software/social/
  29. */
  30. if (!defined('GNUSOCIAL')) {
  31. exit(1);
  32. }
  33. /**
  34. * Class responsible for abstracting media files
  35. */
  36. class MediaFile
  37. {
  38. public $id = null;
  39. public $filepath = null;
  40. public $filename = null;
  41. public $fileRecord = null;
  42. public $fileurl = null;
  43. public $short_fileurl = null;
  44. public $mimetype = null;
  45. /**
  46. * @param string $filepath The path of the file this media refers to. Required
  47. * @param string $mimetype The mimetype of the file. Required
  48. * @param $filehash The hash of the file, if known. Optional
  49. * @param int|null $id The DB id of the file. Int if known, null if not.
  50. * If null, it searches for it. If -1, it skips all DB
  51. * interactions (useful for temporary objects)
  52. * @throws ClientException
  53. * @throws NoResultException
  54. * @throws ServerException
  55. */
  56. public function __construct(string $filepath, string $mimetype, $filehash = null, $id = null)
  57. {
  58. $this->filepath = $filepath;
  59. $this->filename = basename($this->filepath);
  60. $this->mimetype = $mimetype;
  61. $this->filehash = self::getHashOfFile($this->filepath, $filehash);
  62. $this->id = $id;
  63. // If id is -1, it means we're dealing with a temporary object and don't want to store it in the DB,
  64. // or add redirects
  65. if ($this->id !== -1) {
  66. if (!empty($this->id)) {
  67. // If we have an id, load it
  68. $this->fileRecord = new File();
  69. $this->fileRecord->id = $this->id;
  70. if (!$this->fileRecord->find(true)) {
  71. // If we have set an ID, we need that ID to exist!
  72. throw new NoResultException($this->fileRecord);
  73. }
  74. } else {
  75. // Otherwise, store it
  76. $this->fileRecord = $this->storeFile();
  77. }
  78. $this->fileurl = common_local_url(
  79. 'attachment',
  80. array('attachment' => $this->fileRecord->id)
  81. );
  82. $this->maybeAddRedir($this->fileRecord->id, $this->fileurl);
  83. $this->short_fileurl = common_shorten_url($this->fileurl);
  84. $this->maybeAddRedir($this->fileRecord->id, $this->short_fileurl);
  85. }
  86. }
  87. public function attachToNotice(Notice $notice)
  88. {
  89. File_to_post::processNew($this->fileRecord, $notice);
  90. }
  91. public function getPath()
  92. {
  93. return File::path($this->filename);
  94. }
  95. public function shortUrl()
  96. {
  97. return $this->short_fileurl;
  98. }
  99. public function getEnclosure()
  100. {
  101. return $this->getFile()->getEnclosure();
  102. }
  103. public function delete()
  104. {
  105. @unlink($this->filepath);
  106. }
  107. public function getFile()
  108. {
  109. if (!$this->fileRecord instanceof File) {
  110. throw new ServerException('File record did not exist for MediaFile');
  111. }
  112. return $this->fileRecord;
  113. }
  114. /**
  115. * Calculate the hash of a file.
  116. *
  117. * This won't work for files >2GiB because PHP uses only 32bit.
  118. * @param string $filepath
  119. * @param string|null $filehash
  120. * @return string
  121. * @throws ServerException
  122. */
  123. public static function getHashOfFile(string $filepath, $filehash = null)
  124. {
  125. assert(!empty($filepath), __METHOD__ . ": filepath cannot be null");
  126. if ($filehash === null) {
  127. // Calculate if we have an older upload method somewhere (Qvitter) that
  128. // doesn't do this before calling new MediaFile on its local files...
  129. $filehash = hash_file(File::FILEHASH_ALG, $filepath);
  130. if ($filehash === false) {
  131. throw new ServerException('Could not read file for hashing');
  132. }
  133. }
  134. return $filehash;
  135. }
  136. /**
  137. * Retrieve or insert as a file in the DB
  138. *
  139. * @return object File
  140. * @throws ClientException
  141. * @throws ServerException
  142. */
  143. protected function storeFile()
  144. {
  145. try {
  146. $file = File::getByHash($this->filehash);
  147. // We're done here. Yes. Already. We assume sha256 won't collide on us anytime soon.
  148. return $file;
  149. } catch (NoResultException $e) {
  150. // Well, let's just continue below.
  151. }
  152. $fileurl = File::url($this->filename);
  153. $file = new File;
  154. $file->filename = $this->filename;
  155. $file->urlhash = File::hashurl($fileurl);
  156. $file->url = $fileurl;
  157. $file->filehash = $this->filehash;
  158. $file->size = filesize($this->filepath);
  159. if ($file->size === false) {
  160. throw new ServerException('Could not read file to get its size');
  161. }
  162. $file->date = time();
  163. $file->mimetype = $this->mimetype;
  164. $file_id = $file->insert();
  165. if ($file_id===false) {
  166. common_log_db_error($file, "INSERT", __FILE__);
  167. // TRANS: Client exception thrown when a database error was thrown during a file upload operation.
  168. throw new ClientException(_('There was a database error while saving your file. Please try again.'));
  169. }
  170. // Set file geometrical properties if available
  171. try {
  172. $image = ImageFile::fromFileObject($file);
  173. $orig = clone($file);
  174. $file->width = $image->width;
  175. $file->height = $image->height;
  176. $file->update($orig);
  177. // We have to cleanup after ImageFile, since it
  178. // may have generated a temporary file from a
  179. // video support plugin or something.
  180. // FIXME: Do this more automagically.
  181. if ($image->getPath() != $file->getPath()) {
  182. $image->unlink();
  183. }
  184. } catch (ServerException $e) {
  185. // We just couldn't make out an image from the file. This
  186. // does not have to be UnsupportedMediaException, as we can
  187. // also get ServerException from files not existing etc.
  188. }
  189. return $file;
  190. }
  191. public function rememberFile($file, $short)
  192. {
  193. $this->maybeAddRedir($file->id, $short);
  194. }
  195. /**
  196. * Adds Redir if needed.
  197. *
  198. * @param $file_id
  199. * @param $url
  200. * @return bool false if no need to add, true if added
  201. * @throws ClientException If failed adding
  202. */
  203. public function maybeAddRedir($file_id, $url)
  204. {
  205. try {
  206. File_redirection::getByUrl($url);
  207. return false;
  208. } catch (NoResultException $e) {
  209. $file_redir = new File_redirection;
  210. $file_redir->urlhash = File::hashurl($url);
  211. $file_redir->url = $url;
  212. $file_redir->file_id = $file_id;
  213. $result = $file_redir->insert();
  214. if ($result===false) {
  215. common_log_db_error($file_redir, "INSERT", __FILE__);
  216. // TRANS: Client exception thrown when a database error was thrown during a file upload operation.
  217. throw new ClientException(_('There was a database error while saving your file. Please try again.'));
  218. }
  219. return $result;
  220. }
  221. }
  222. /**
  223. * The maximum allowed file size, as a string
  224. */
  225. public static function maxFileSize()
  226. {
  227. $value = self::maxFileSizeInt();
  228. if ($value > 1024 * 1024) {
  229. $value = $value/(1024*1024);
  230. // TRANS: Number of megabytes. %d is the number.
  231. return sprintf(_m('%dMB', '%dMB', $value), $value);
  232. } elseif ($value > 1024) {
  233. $value = $value/1024;
  234. // TRANS: Number of kilobytes. %d is the number.
  235. return sprintf(_m('%dkB', '%dkB', $value), $value);
  236. } else {
  237. // TRANS: Number of bytes. %d is the number.
  238. return sprintf(_m('%dB', '%dB', $value), $value);
  239. }
  240. }
  241. /**
  242. * The maximum allowed file size, as an int
  243. */
  244. public static function maxFileSizeInt()
  245. {
  246. return min(
  247. self::sizeStrToInt(ini_get('post_max_size')),
  248. self::sizeStrToInt(ini_get('upload_max_filesize')),
  249. self::sizeStrToInt(ini_get('memory_limit'))
  250. );
  251. }
  252. /**
  253. * Convert a string representing a file size (with units), to an int
  254. * @param $str
  255. * @return bool|int|string
  256. */
  257. public static function sizeStrToInt($str)
  258. {
  259. $unit = substr($str, -1);
  260. $num = substr($str, 0, -1);
  261. switch (strtoupper($unit)) {
  262. case 'G':
  263. $num *= 1024;
  264. // no break
  265. case 'M':
  266. $num *= 1024;
  267. // no break
  268. case 'K':
  269. $num *= 1024;
  270. }
  271. return $num;
  272. }
  273. /**
  274. * Create a new MediaFile or ImageFile object from an upload
  275. *
  276. * Tries to set the mimetype correctly, using the most secure method available and rejects the file otherwise.
  277. * In case the upload is an image, this function returns an new ImageFile (which extends MediaFile)
  278. * @param string $param
  279. * @param Profile|null $scoped
  280. * @return ImageFile|MediaFile
  281. * @throws ClientException
  282. * @throws NoResultException
  283. * @throws NoUploadedMediaException
  284. * @throws ServerException
  285. * @throws UnsupportedMediaException
  286. * @throws UseFileAsThumbnailException
  287. */
  288. public static function fromUpload(string $param='media', Profile $scoped=null)
  289. {
  290. // The existence of the "error" element means PHP has processed it properly even if it was ok.
  291. if (!isset($_FILES[$param]) || !isset($_FILES[$param]['error'])) {
  292. throw new NoUploadedMediaException($param);
  293. }
  294. switch ($_FILES[$param]['error']) {
  295. case UPLOAD_ERR_OK: // success, jump out
  296. break;
  297. case UPLOAD_ERR_INI_SIZE:
  298. case UPLOAD_ERR_FORM_SIZE:
  299. // TRANS: Exception thrown when too large a file is uploaded.
  300. // TRANS: %s is the maximum file size, for example "500b", "10kB" or "2MB".
  301. throw new ClientException(sprintf(
  302. _('That file is too big. The maximum file size is %s.'),
  303. self::maxFileSize()
  304. ));
  305. case UPLOAD_ERR_PARTIAL:
  306. @unlink($_FILES[$param]['tmp_name']);
  307. // TRANS: Client exception.
  308. throw new ClientException(_('The uploaded file was only partially uploaded.'));
  309. case UPLOAD_ERR_NO_FILE:
  310. // No file; probably just a non-AJAX submission.
  311. throw new NoUploadedMediaException($param);
  312. case UPLOAD_ERR_NO_TMP_DIR:
  313. // TRANS: Client exception thrown when a temporary folder is not present to store a file upload.
  314. throw new ClientException(_('Missing a temporary folder.'));
  315. case UPLOAD_ERR_CANT_WRITE:
  316. // TRANS: Client exception thrown when writing to disk is not possible during a file upload operation.
  317. throw new ClientException(_('Failed to write file to disk.'));
  318. case UPLOAD_ERR_EXTENSION:
  319. // TRANS: Client exception thrown when a file upload operation has been stopped by an extension.
  320. throw new ClientException(_('File upload stopped by extension.'));
  321. default:
  322. common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " . $_FILES[$param]['error']);
  323. // TRANS: Client exception thrown when a file upload operation has failed with an unknown reason.
  324. throw new ClientException(_('System error uploading file.'));
  325. }
  326. $filehash = strtolower(self::getHashOfFile($_FILES[$param]['tmp_name']));
  327. try {
  328. $file = File::getByHash($filehash);
  329. // If no exception is thrown the file exists locally, so we'll use that and just add redirections.
  330. // but if the _actual_ locally stored file doesn't exist, getPath will throw FileNotFoundException
  331. $filepath = $file->getPath();
  332. $mimetype = $file->mimetype;
  333. // XXX PHP: Upgrade to PHP 7.1
  334. // catch (FileNotFoundException | NoResultException $e)
  335. } catch (Exception $e) {
  336. // We have to save the upload as a new local file. This is the normal course of action.
  337. if ($scoped instanceof Profile) {
  338. // Throws exception if additional size does not respect quota
  339. // This test is only needed, of course, if we're uploading something new.
  340. File::respectsQuota($scoped, $_FILES[$param]['size']);
  341. }
  342. $mimetype = self::getUploadedMimeType($_FILES[$param]['tmp_name'], $_FILES[$param]['name']);
  343. $media = common_get_mime_media($mimetype);
  344. $basename = basename($_FILES[$param]['name']);
  345. $filename = $filehash . '.' . File::guessMimeExtension($mimetype, $basename);
  346. $filepath = File::path($filename);
  347. $result = move_uploaded_file($_FILES[$param]['tmp_name'], $filepath);
  348. if (!$result) {
  349. // TRANS: Client exception thrown when a file upload operation fails because the file could
  350. // TRANS: not be moved from the temporary folder to the permanent file location.
  351. // UX: too specific
  352. throw new ClientException(_('File could not be moved to destination directory.'));
  353. }
  354. if ($media === 'image') {
  355. // Use -1 for the id to avoid adding this temporary file to the DB
  356. $img = new ImageFile(-1, $filepath);
  357. // Validate the image by reencoding it. Additionally normalizes old formats to PNG,
  358. // keeping JPEG and GIF untouched
  359. $outpath = $img->resizeTo($img->filepath);
  360. $ext = image_type_to_extension($img->preferredType());
  361. $filename = $filehash . $ext;
  362. $filepath = File::path($filename);
  363. $result = rename($outpath, $filepath);
  364. return new ImageFile(null, $filepath);
  365. }
  366. }
  367. return new MediaFile($filepath, $mimetype, $filehash);
  368. }
  369. public static function fromFilehandle($fh, Profile $scoped=null)
  370. {
  371. $stream = stream_get_meta_data($fh);
  372. // So far we're only handling filehandles originating from tmpfile(),
  373. // so we can always do hash_file on $stream['uri'] as far as I can tell!
  374. $filehash = hash_file(File::FILEHASH_ALG, $stream['uri']);
  375. try {
  376. $file = File::getByHash($filehash);
  377. // Already have it, so let's reuse the locally stored File
  378. // by using getPath we also check whether the file exists
  379. // and throw a FileNotFoundException with the path if it doesn't.
  380. $filename = basename($file->getPath());
  381. $mimetype = $file->mimetype;
  382. } catch (FileNotFoundException $e) {
  383. // This happens if the file we have uploaded has disappeared
  384. // from the local filesystem for some reason. Since we got the
  385. // File object from a sha256 check in fromFilehandle, it's safe
  386. // to just copy the uploaded data to disk!
  387. fseek($fh, 0); // just to be sure, go to the beginning
  388. // dump the contents of our filehandle to the path from our exception
  389. // and report error if it failed.
  390. if (false === file_put_contents($e->path, fread($fh, filesize($stream['uri'])))) {
  391. // TRANS: Client exception thrown when a file upload operation fails because the file could
  392. // TRANS: not be moved from the temporary folder to the permanent file location.
  393. throw new ClientException(_('File could not be moved to destination directory.'));
  394. }
  395. if (!chmod($e->path, 0664)) {
  396. common_log(LOG_ERR, 'Could not chmod uploaded file: '._ve($e->path));
  397. }
  398. $filename = basename($file->getPath());
  399. $mimetype = $file->mimetype;
  400. } catch (NoResultException $e) {
  401. if ($scoped instanceof Profile) {
  402. File::respectsQuota($scoped, filesize($stream['uri']));
  403. }
  404. $mimetype = self::getUploadedMimeType($stream['uri']);
  405. $filename = strtolower($filehash) . '.' . File::guessMimeExtension($mimetype);
  406. $filepath = File::path($filename);
  407. $result = copy($stream['uri'], $filepath) && chmod($filepath, 0664);
  408. if (!$result) {
  409. common_log(LOG_ERR, 'File could not be moved (or chmodded) from '._ve($stream['uri']) . ' to ' . _ve($filepath));
  410. // TRANS: Client exception thrown when a file upload operation fails because the file could
  411. // TRANS: not be moved from the temporary folder to the permanent file location.
  412. throw new ClientException(_('File could not be moved to destination directory.'));
  413. }
  414. }
  415. return new MediaFile($filename, $mimetype, $filehash);
  416. }
  417. /**
  418. * Attempt to identify the content type of a given file.
  419. *
  420. * @param string $filepath filesystem path as string (file must exist)
  421. * @param bool $originalFilename (optional) for extension-based detection
  422. * @return string
  423. *
  424. * @throws ClientException if type is known, but not supported for local uploads
  425. * @throws ServerException
  426. * @fixme this seems to tie a front-end error message in, kinda confusing
  427. *
  428. */
  429. public static function getUploadedMimeType(string $filepath, $originalFilename=false)
  430. {
  431. // We only accept filenames to existing files
  432. $mimetype = null;
  433. // From CodeIgniter
  434. // We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
  435. $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
  436. /**
  437. * Fileinfo extension - most reliable method
  438. *
  439. * Apparently XAMPP, CentOS, cPanel and who knows what
  440. * other PHP distribution channels EXPLICITLY DISABLE
  441. * ext/fileinfo, which is otherwise enabled by default
  442. * since PHP 5.3 ...
  443. */
  444. if (function_exists('finfo_file')) {
  445. $finfo = @finfo_open(FILEINFO_MIME);
  446. // It is possible that a FALSE value is returned, if there is no magic MIME database
  447. // file found on the system
  448. if (is_resource($finfo)) {
  449. $mime = @finfo_file($finfo, $filepath);
  450. finfo_close($finfo);
  451. /* According to the comments section of the PHP manual page,
  452. * it is possible that this function returns an empty string
  453. * for some files (e.g. if they don't exist in the magic MIME database)
  454. */
  455. if (is_string($mime) && preg_match($regexp, $mime, $matches)) {
  456. $mimetype = $matches[1];
  457. }
  458. }
  459. }
  460. /* This is an ugly hack, but UNIX-type systems provide a "native" way to detect the file type,
  461. * which is still more secure than depending on the value of $_FILES[$field]['type'], and as it
  462. * was reported in issue #750 (https://github.com/EllisLab/CodeIgniter/issues/750) - it's better
  463. * than mime_content_type() as well, hence the attempts to try calling the command line with
  464. * three different functions.
  465. *
  466. * Notes:
  467. * - the DIRECTORY_SEPARATOR comparison ensures that we're not on a Windows system
  468. * - many system admins would disable the exec(), shell_exec(), popen() and similar functions
  469. * due to security concerns, hence the function_usable() checks
  470. */
  471. if (DIRECTORY_SEPARATOR !== '\\') {
  472. $cmd = 'file --brief --mime '.escapeshellarg($filepath).' 2>&1';
  473. if (function_exists('exec')) {
  474. /* This might look confusing, as $mime is being populated with all of the output
  475. * when set in the second parameter. However, we only need the last line, which is
  476. * the actual return value of exec(), and as such - it overwrites anything that could
  477. * already be set for $mime previously. This effectively makes the second parameter a
  478. * dummy value, which is only put to allow us to get the return status code.
  479. */
  480. $mime = @exec($cmd, $mime, $return_status);
  481. if ($return_status === 0 && is_string($mime) && preg_match($regexp, $mime, $matches)) {
  482. $mimetype = $matches[1];
  483. }
  484. }
  485. if (function_exists('shell_exec')) {
  486. $mime = @shell_exec($cmd);
  487. if (strlen($mime) > 0) {
  488. $mime = explode("\n", trim($mime));
  489. if (preg_match($regexp, $mime[(count($mime) - 1)], $matches)) {
  490. $mimetype = $matches[1];
  491. }
  492. }
  493. }
  494. if (function_exists('popen')) {
  495. $proc = @popen($cmd, 'r');
  496. if (is_resource($proc)) {
  497. $mime = @fread($proc, 512);
  498. @pclose($proc);
  499. if ($mime !== false) {
  500. $mime = explode("\n", trim($mime));
  501. if (preg_match($regexp, $mime[(count($mime) - 1)], $matches)) {
  502. $mimetype = $matches[1];
  503. }
  504. }
  505. }
  506. }
  507. }
  508. // Fall back to mime_content_type(), if available (still better than $_FILES[$field]['type'])
  509. if (function_exists('mime_content_type')) {
  510. $mimetype = @mime_content_type($filepath);
  511. // It's possible that mime_content_type() returns FALSE or an empty string
  512. if ($mimetype == false && strlen($mimetype) > 0) {
  513. throw new ServerException(_m('Could not determine file\'s MIME type.'));
  514. }
  515. }
  516. // Unclear types are such that we can't really tell by the auto
  517. // detect what they are (.bin, .exe etc. are just "octet-stream")
  518. $unclearTypes = array('application/octet-stream',
  519. 'application/vnd.ms-office',
  520. 'application/zip',
  521. 'text/plain',
  522. 'text/html', // Ironically, Wikimedia Commons' SVG_logo.svg is identified as text/html
  523. // TODO: for XML we could do better content-based sniffing too
  524. 'text/xml');
  525. $supported = common_config('attachments', 'supported');
  526. // If we didn't match, or it is an unclear match
  527. if ($originalFilename && (!$mimetype || in_array($mimetype, $unclearTypes))) {
  528. try {
  529. $type = common_supported_filename_to_mime($originalFilename);
  530. return $type;
  531. } catch (UnknownExtensionMimeException $e) {
  532. // FIXME: I think we should keep the file extension here (supported should be === true here)
  533. } catch (Exception $e) {
  534. // Extension parsed but no connected mimetype, so $mimetype is our best guess
  535. }
  536. }
  537. // If $config['attachments']['supported'] equals boolean true, accept any mimetype
  538. if ($supported === true || array_key_exists($mimetype, $supported)) {
  539. // FIXME: Don't know if it always has a mimetype here because
  540. // finfo->file CAN return false on error: http://php.net/finfo_file
  541. // so if $supported === true, this may return something unexpected.
  542. return $mimetype;
  543. }
  544. // We can conclude that we have failed to get the MIME type
  545. $media = common_get_mime_media($mimetype);
  546. if ('application' !== $media) {
  547. // TRANS: Client exception thrown trying to upload a forbidden MIME type.
  548. // TRANS: %1$s is the file type that was denied, %2$s is the application part of
  549. // TRANS: the MIME type that was denied.
  550. $hint = sprintf(_('"%1$s" is not a supported file type on this server. ' .
  551. 'Try using another %2$s format.'), $mimetype, $media);
  552. } else {
  553. // TRANS: Client exception thrown trying to upload a forbidden MIME type.
  554. // TRANS: %s is the file type that was denied.
  555. $hint = sprintf(_('"%s" is not a supported file type on this server.'), $mimetype);
  556. }
  557. throw new ClientException($hint);
  558. }
  559. }