mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
rename before upload to image hosting server
This commit is contained in:
@@ -23,9 +23,23 @@ abstract class Storage {
|
|||||||
abstract function getBaseUrl(): string;
|
abstract function getBaseUrl(): string;
|
||||||
abstract function getDriverName(): string;
|
abstract function getDriverName(): string;
|
||||||
|
|
||||||
public function uploadGetLocation(string $filepath): string
|
public function uploadGetLocation(string $filepath, string $originalName): string
|
||||||
{
|
{
|
||||||
$url = $this->upload($filepath);
|
$extension = pathinfo($filepath, PATHINFO_EXTENSION);
|
||||||
|
if (empty($extension)) {
|
||||||
|
$newFilepath = sprintf("%s/%s", dirname($filepath), trim($originalName));
|
||||||
|
$moveResult = move_uploaded_file($filepath, $newFilepath);
|
||||||
|
do_log(sprintf("filepath: %s, newFilepath: %s, moveResult: %s", $filepath, $newFilepath, $moveResult));
|
||||||
|
if (!$moveResult) {
|
||||||
|
throw new \Exception("Failed to move uploaded file.");
|
||||||
|
}
|
||||||
|
$url = $this->upload($newFilepath);
|
||||||
|
@unlink($filepath);
|
||||||
|
@unlink($newFilepath);
|
||||||
|
} else {
|
||||||
|
$url = $this->upload($filepath);
|
||||||
|
@unlink($filepath);
|
||||||
|
}
|
||||||
return $this->trimBaseUrl($url);
|
return $this->trimBaseUrl($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ if ($Attach->enable_attachment())
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$driver = \Nexus\Attachment\Storage::getDriver();
|
$driver = \Nexus\Attachment\Storage::getDriver();
|
||||||
$location = $driver->uploadGetLocation($file["tmp_name"]);
|
$location = $driver->uploadGetLocation($file["tmp_name"], $file['name']);
|
||||||
$db_file_location = substr($location, 0, -1*strlen($ext)-1);
|
$db_file_location = substr($location, 0, -1*strlen($ext)-1);
|
||||||
$url = $driver->getImageUrl($location);
|
$url = $driver->getImageUrl($location);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user