X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fmediafile.php;h=54d00b4acfefff266b7e1a600340181ff45be172;hb=7ca0ff9a19d1d87dadc836659aa1c02e6e7c375c;hp=be97b1cc17ea8c6241e00679e6fd2ddeec102a72;hpb=1db02d7f367f47703d53f0d730a49f397305961e;p=quix0rs-gnu-social.git diff --git a/lib/mediafile.php b/lib/mediafile.php index be97b1cc17..54d00b4acf 100644 --- a/lib/mediafile.php +++ b/lib/mediafile.php @@ -34,8 +34,6 @@ if (!defined('GNUSOCIAL')) { exit(1); } class MediaFile { - protected $scoped = null; - var $filename = null; var $fileRecord = null; var $fileurl = null; @@ -236,7 +234,20 @@ class MediaFile try { $file = File::getByHash($filehash); // If no exception is thrown the file exists locally, so we'll use that and just add redirections. - $filename = $file->filename; + // but if the _actual_ locally stored file doesn't exist, getPath will throw FileNotFoundException + $filename = basename($file->getPath()); + $mimetype = $file->mimetype; + + } catch (FileNotFoundException $e) { + // The file does not exist in our local filesystem, so store this upload. + + if (!move_uploaded_file($_FILES[$param]['tmp_name'], $e->path)) { + // TRANS: Client exception thrown when a file upload operation fails because the file could + // TRANS: not be moved from the temporary folder to the permanent file location. + throw new ClientException(_('File could not be moved to destination directory.')); + } + + $filename = basename($file->getPath()); $mimetype = $file->mimetype; } catch (NoResultException $e) {