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
+6 -24
View File
@@ -131,34 +131,16 @@ class NextCloudHelper
public static function getFileUrl($filePath) public static function getFileUrl($filePath)
{ {
$baseUrl = env('NEXT_CLOUD_URL'); $baseUrl = env('NEXT_CLOUD_URL');
$publicToken = '5ogLDbQEbEMsAbD'; // Replace with your actual token $username = env('NEXT_CLOUD_USERNAME');
$relativePath = "/mktia/public.php/webdav/" . ltrim($filePath, '/');
// Build the full URL // Build the user-specific WebDAV file URL
$url = rtrim($baseUrl, '/') . $relativePath . "?token={$publicToken}"; $relativePath = "/mktia/remote.php/dav/files/{$username}/" . ltrim($filePath, '/');
// Initialize cURL // Return the full accessible URL
$ch = curl_init($url); return rtrim($baseUrl, '/') . '/' . $relativePath;
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}");
}
curl_close($ch);
return $url;
} }
public static function getNextcloudFile($filePath) public static function getNextcloudFile($filePath)
{ {
// Check if the file exists // Check if the file exists
@@ -119,7 +119,7 @@
<td>{{ number_format($item->total, 0, ',', '.') }}</td> <td>{{ number_format($item->total, 0, ',', '.') }}</td>
<td> <td>
@if ($item->bukti1) @if ($item->bukti1)
<a href="{{ NextCloudHelper::getNextcloudFile($item->bukti1) }}" target="_blank"> <a href="{{ NextCloudHelper::getFileUrl($item->bukti1) }}" target="_blank">
Download Download
</a> </a>
@else @else