Skip to content

Commit 278e7cd

Browse files
authored
Added methods publicPath and url
1 parent a1c1b71 commit 278e7cd

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

src/FS.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,13 @@ public static function uploadFile($file, $path, $config = [])
422422
"category" => $file_category,
423423
"path" => $target_file,
424424
"parent_directory" => basename(dirname($target_file)),
425-
"parent_directory_path" => $target_dir
425+
"parent_directory_path" => $target_dir,
426+
"public_path" => self::publicPath($target_file),
427+
"url" => self::url($target_file)
426428
];
427429

428430
if (move_uploaded_file($temp, $target_file)) {
431+
self::$uploadInfo[$name]["status"] = true;
429432
return $name;
430433
} else {
431434
self::$errorsArray["upload"] = "Wasn't able to upload $file_category";
@@ -666,4 +669,28 @@ public static function errors(): array
666669
{
667670
return self::$errorsArray;
668671
}
672+
673+
/**
674+
* Public path
675+
* Returns a public accessible path for application uploaded files
676+
*
677+
* @param string $path
678+
* @return string
679+
*/
680+
public static function publicPath($path = "")
681+
{
682+
return str_replace("storage/app/", "", $path);
683+
}
684+
685+
/**
686+
* Get a file url
687+
*
688+
* @param string $path
689+
* @return string
690+
*/
691+
public static function url($path)
692+
{
693+
$publicPath = StoragePath(self::publicPath($path));
694+
return getenv("APP_URL") . $publicPath;
695+
}
669696
}

0 commit comments

Comments
 (0)