Steve
Steve

Reputation: 1046

Module multi image upload

I'm using the following module for uploading multiple images: https://github.com/bummzack/sortablefile

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?

Thank you

Upvotes: 1

Views: 594

Answers (2)

LevB
LevB

Reputation: 2366

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.

Upvotes: 0

Bhong Ong
Bhong Ong

Reputation: 11

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.

Upvotes: 1

Related Questions