revert function to get image url

This commit is contained in:
Jagad R R
2024-12-31 12:46:14 +07:00
parent 3f7b9d0eb5
commit fbcc841e80
2 changed files with 7 additions and 25 deletions
+5 -23
View File
@@ -131,33 +131,15 @@ class NextCloudHelper
public static function getFileUrl($filePath)
{
$baseUrl = env('NEXT_CLOUD_URL');
$publicToken = '5ogLDbQEbEMsAbD'; // Replace with your actual token
$relativePath = "/mktia/public.php/webdav/" . ltrim($filePath, '/');
$username = env('NEXT_CLOUD_USERNAME');
// Build the full URL
$url = rtrim($baseUrl, '/') . $relativePath . "?token={$publicToken}";
// Build the user-specific WebDAV file URL
$relativePath = "/mktia/remote.php/dav/files/{$username}/" . ltrim($filePath, '/');
// Initialize cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'OCS-APIRequest: true', // Ensure Nextcloud recognizes the API request
]);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification
$response = curl_exec($ch);
// Handle cURL errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
throw new \Exception("cURL error: {$error}");
// Return the full accessible URL
return rtrim($baseUrl, '/') . '/' . $relativePath;
}
curl_close($ch);
return $url;
}
public static function getNextcloudFile($filePath)
{
@@ -119,7 +119,7 @@
<td>{{ number_format($item->total, 0, ',', '.') }}</td>
<td>
@if ($item->bukti1)
<a href="{{ NextCloudHelper::getNextcloudFile($item->bukti1) }}" target="_blank">
<a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}" target="_blank">
Download
</a>
@else