From bfeb41fdf16c958f3ba0238a900bd37b2b76549b Mon Sep 17 00:00:00 2001 From: simonpipe Date: Wed, 7 Jan 2026 19:14:15 +0100 Subject: [PATCH] Update mastodonapi.php --- mastodonapi.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mastodonapi.php b/mastodonapi.php index d4323d9..d8701f6 100644 --- a/mastodonapi.php +++ b/mastodonapi.php @@ -109,7 +109,10 @@ class YellowMastodonapi { $fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md"; $fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName; if ( file_exists($fullPath) ) continue; - if ( !is_dir(dirname($fullPath)) ) mkdir(dirname($fullPath), 0755, true); + if ( !is_dir(dirname($fullPath)) ) { + mkdir(dirname($fullPath), 0777, true); + chmod(dirname($fullPath), 0777); + } $imageFilenames = array(); $imageAltTexts = array(); foreach ( $post["media_attachments"] ?? array() as $media ) { @@ -137,10 +140,17 @@ class YellowMastodonapi { private function downloadAndSaveImage($media, $dirPath) { $imageUrl = $media["remote_url"] ?? $media["url"] ?? $media["preview_url"] ?? null; if ( empty($imageUrl) ) return false; - if ( !is_dir($dirPath) ) mkdir($dirPath, 0755, true); + + if ( !is_dir($dirPath) ) { + mkdir($dirPath, 0777, true); + chmod($dirPath, 0777); + } + $fileName = basename(parse_url($imageUrl, PHP_URL_PATH)); $fullPath = $dirPath . $fileName; + if ( file_exists($fullPath) ) return $fileName; + $ch = curl_init($imageUrl); curl_setopt_array($ch, array( CURLOPT_RETURNTRANSFER => true, @@ -151,6 +161,7 @@ class YellowMastodonapi { )); $imgData = curl_exec($ch); curl_close($ch); + if ( !$imgData ) return false; file_put_contents($fullPath, $imgData); return $fileName;