I'm using the following module for uploading multiple images:
I use the has-many relationship.
class PortfolioPage extends Page
private static $has_many = array(
'Images' => 'PortfolioImage'
class PortfolioImage extends Image
private static $has_one = array(
'PortfolioPage' => 'PortfolioPage'
The problem is that when uploading multiple images with the same file name it gives me the following error: File with the same name already exists .
How can I avoid this such that it will be possible to upload multiple images when they have the same filename?
Actually this error is "natural" behavior, it's impossible to store multiple files with identical names in one directory.
Please read discussion on GitHub for more information.
SortableUploadField is extending the UploadField, try adding setOverwriteWarning to False in your getCMSFields section. Check the code below:
$uploadField = new SortableUploadField('Images', 'Upload Images'); $uploadField->setOverwriteWarning(FALSE); $fields->addFieldToTab("Root.Main", $uploadField);
Take note, this only prevents the error and rename the duplicate file name. Example: if you upload same file name like file.jpg, the second file.jpg will be renamed to 2.jpg, 3.jpg, etc.