diff --git a/actions/apiaccountupdateprofilebanner.php b/actions/apiaccountupdateprofilebanner.php index aa7a606..280c961 100644 --- a/actions/apiaccountupdateprofilebanner.php +++ b/actions/apiaccountupdateprofilebanner.php @@ -37,6 +37,7 @@ · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ +require_once INSTALLDIR . '/lib/util/tempfile.php'; if (!defined('GNUSOCIAL')) { exit(1); @@ -93,12 +94,13 @@ class ApiAccountUpdateProfileBannerAction extends ApiAuthAction $this->img = str_replace(' ', '+', $this->img); $this->img = base64_decode($this->img, true); - $fh = tmpfile(); - fwrite($fh, $this->img); + $fh = new TemporaryFile('gs-mediaupload'); + fwrite($fh->getResource(), $this->img); unset($this->img); - fseek($fh, 0); - $mediafile = MediaFile::fromFilehandle($fh, $this->scoped); + fflush($fh->getResouce()); + $mediafile = MediaFile::fromFileInfo($fh, $this->scoped); + unset($fh); } // maybe resize diff --git a/actions/apiupdateavatar.php b/actions/apiupdateavatar.php index b234b55..fdb54bb 100644 --- a/actions/apiupdateavatar.php +++ b/actions/apiupdateavatar.php @@ -37,6 +37,7 @@ · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ +require_once INSTALLDIR . '/lib/util/tempfile.php'; if (!defined('GNUSOCIAL')) { exit(1); @@ -90,15 +91,14 @@ class ApiUpdateAvatarAction extends ApiAuthAction $imagefile = null; // write the image to a temporary file - $fh = tmpfile(); - fwrite($fh, $this->img); + $fh = new TemporaryFile('gs-mediaupload'); + fwrite($fh->getResource(), $this->img); unset($this->img); // no need to keep it in memory - // seek back to position 0, so we don't read EOF directly - fseek($fh, 0); // read the temporary file as an uploaded image, will store File object - $mediafile = MediaFile::fromFilehandle($fh, $this->scoped); - // Deletes the temporary file, if it was needed we stored it in fromFilehandle - fclose($fh); + fflush($fh->getResource()); + $mediafile = MediaFile::fromFileInfo($fh, $this->scoped); + // Deletes the temporary file, if it was needed we stored it in fromFileInfo + unset($fh); // Now try to get it as an ImageFile since it has some handy functions $imagefile = ImageFile::fromFileObject($mediafile->fileRecord); diff --git a/actions/apiupdatebackgroundimage.php b/actions/apiupdatebackgroundimage.php index e71f24e..cad44e0 100644 --- a/actions/apiupdatebackgroundimage.php +++ b/actions/apiupdatebackgroundimage.php @@ -37,6 +37,7 @@ · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ +require_once INSTALLDIR . '/lib/util/tempfile.php'; if (!defined('GNUSOCIAL')) { exit(1); @@ -91,15 +92,15 @@ class ApiUpdateBackgroundImageAction extends ApiAuthAction $imagefile = null; // put the image data in a temporary file - $fh = tmpfile(); - fwrite($fh, $this->img); + $fh = new TemporaryFile('gs-mediaupload') + fwrite($fh->getResource(), $this->img); unset($this->img); - fseek($fh, 0); // go to beginning just to be sure the content is read properly // We get a MediaFile with a File object using the filehandle - $mediafile = MediaFile::fromFilehandle($fh, $this->scoped); + fflush($fh->getResource()); + $mediafile = MediaFile::fromFileInfo($fh, $this->scoped); // and can dispose of the temporary filehandle since we're certain we have a File on disk now - fclose($fh); + unset($fh); $imagefile = ImageFile::fromFileObject($mediafile->fileRecord); unset($mediafile); // No need to keep the MediaFile around anymore, everything we need is in ImageFile