diff --git a/resources/views/public/blogs/show.blade.php b/resources/views/public/blogs/show.blade.php
index dfd1a3e..c9a7f79 100644
--- a/resources/views/public/blogs/show.blade.php
+++ b/resources/views/public/blogs/show.blade.php
@@ -43,47 +43,66 @@
]);
// Get the absolute URL for images with strict checking
- $baseUrl = config('app.url');
+ $baseUrl = rtrim(config('app.url'), '/');
$imageUrl = '';
$defaultLogo = $baseUrl . '/meetmytech_logo.jpg';
+ $meetMytechFavicon = $baseUrl . '/favicon.ico';
// Function to verify image existence and accessibility
function verifyImage($url) {
if (empty($url)) return false;
- // URL encode spaces and special characters
- $encodedUrl = str_replace(' ', '%20', $url);
+ try {
+ // URL encode spaces and special characters
+ $encodedUrl = str_replace(' ', '%20', $url);
+
+ // Handle both HTTP and HTTPS
+ if (!preg_match('~^(?:f|ht)tps?://~i', $encodedUrl)) {
+ $encodedUrl = 'https://' . ltrim($encodedUrl, '/');
+ }
- // For absolute URLs
- $headers = @get_headers($encodedUrl);
- return $headers && strpos($headers[0], '200') !== false;
+ // For absolute URLs
+ $headers = @get_headers($encodedUrl);
+ $isAccessible = $headers && strpos($headers[0], '200') !== false;
+
+ Log::info('Image verification', [
+ 'url' => $url,
+ 'encoded_url' => $encodedUrl,
+ 'accessible' => $isAccessible
+ ]);
+
+ return $isAccessible;
+ } catch (\Exception $e) {
+ Log::error('Image verification failed', [
+ 'url' => $url,
+ 'error' => $e->getMessage()
+ ]);
+ return false;
+ }
}
- // Check featured image
+ // First try the blog's featured image
if ($blog->featured_image) {
- $featuredImageUrl = url(Storage::url($blog->featured_image));
- // URL encode spaces and special characters
- $featuredImageUrl = str_replace(' ', '%20', $featuredImageUrl);
-
- if (verifyImage($featuredImageUrl)) {
- $imageUrl = $featuredImageUrl;
- Log::info('Using featured image: ' . $imageUrl);
+ $featuredImagePath = $blog->featured_image;
+ if (Storage::disk('public')->exists($featuredImagePath)) {
+ $imageUrl = $baseUrl . Storage::url($featuredImagePath);
+ Log::info('Using blog featured image', ['url' => $imageUrl]);
}
}
- // If featured image fails or doesn't exist, use default logo
+ // If featured image is not available or accessible, use default logo
if (empty($imageUrl) || !verifyImage($imageUrl)) {
$imageUrl = $defaultLogo;
- Log::info('Using default logo: ' . $imageUrl);
+ Log::info('Using default MeetMyTech logo', ['url' => $imageUrl]);
}
- // Force HTTPS for production
+ // Ensure HTTPS for production
if (app()->environment('production')) {
- $imageUrl = str_replace('http://', 'https://', $imageUrl);
+ $imageUrl = preg_replace('/^http:/', 'https:', $imageUrl);
}
- // Set favicon
- $meetMytechFavicon = $baseUrl . '/favicon.ico';
+ // URL encode the final image URL
+ $imageUrl = str_replace(' ', '%20', $imageUrl);
// Force HTTPS for production
if (app()->environment('production') && !str_starts_with($imageUrl, 'https://')) {
@@ -104,8 +123,8 @@ function verifyImage($url) {
-
-
+
+