This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I'm uploading an image using the rainlab builder plugin. Say for example the file is called "my_image.jpg" This will get uploaded to storage/uploads/public/56f/809/658/56f809658.jpg This isn't very seo friendly so I want it to keep it's original filename my_image.jpg Any help would be appreciated. thanks
me27744 said: I'm uploading an image using the rainlab builder plugin. Say for example the file is called "my_image.jpg" This will get uploaded to storage/uploads/public/56f/809/658/56f809658.jpg This isn't very seo friendly so I want it to keep it's original filename my_image.jpg
Start by playing with various filename calculating methods from \October\Rain\Database\Attach\File (i.e. getDiskName(), getStorage/PartitionDirectory() and co.)
Override them in your \System\Models\File descendant https://octobercms.com/docs/api/system/models/file
Define your model attach*** relationships with new descendant class \My\Plugin\Models\SeoFile
Thanks,
that worked!!
I created a file in system\models overriding the frompost method. I replaced disk_name with file_name. So now I get the file saved in storage\app\uploads\public\5a7\1b9\b6f\the_original_filename.jpg
############################## namespace System\Models; class MyFile extends File { public function fromPost($uploadedFile) { if ($uploadedFile === null) { return; }
$this->file_name = $uploadedFile->getClientOriginalName();
$this->file_size = $uploadedFile->getClientSize();
$this->content_type = $uploadedFile->getMimeType();
$this->disk_name = $this->getDiskName();
/*
* getRealPath() can be empty for some environments (IIS)
*/
$realPath = empty(trim($uploadedFile->getRealPath()))
? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName()
: $uploadedFile->getRealPath();
//$this->putFile($realPath, $this->disk_name);
$this->putFile($realPath, $this->file_name);
return $this;
} }
Last updated
1-3 of 3