0

Using the Upload Plugin. I want to upload files in a foreign_key folder to "guarantee" random, since it doesn't appear to have any check for an existing file before overwriting a file(s).

I'd like a file to upload to something like:

/webroot/uploads/02/88/06/4f93676e-347c-4e0c-8e6c-0a3cadcd7f7c/my_photo.jpg

When I set 'pathMethod'=>'random', I get the 3 random number (between 0-100) folders, but I don't get the primary key folder.

Or, if I set 'pathMethod'=>'primaryKey', I get the primary key folder, but not the random numbers.

In the Upload behavior of the plugin, there's an uploadSettings function (not sure if that's what it's for), but when I try to run it via my controller, it doesn't do anything:

//ArticleDatasController
$this->Upload->uploadSettings('Upload', 'photo', array('path'=> '{ROOT}webroot{DS}uploads{DS}test{DS}ArticleData{DS}{field}'));
if($this->Upload->save($this->request->data)) {

Here's my Upload model's $actsAs:

//Upload model
public $actsAs = array(
    'Upload.Upload' => array(
        'photo' => array(
            'thumbnailSizes' => array(
                'xvga' => '1024x768',
                'vga' => '640x480',
                'thumb' => '80x80',
            ),
            'thumbnailMethod' => 'php',
            'thumbnailQuality' => '80',
            'pathMethod'=>'random',
            'path' => '{ROOT}webroot{DS}uploads{DS}{field}{DS}',
            'maxSize' => '5242880', //5MB
            'mimetypes' => array('image/jpeg', 'image/png', 'image/gif', 'image/bmp'),
            'extensions' => array('jpg', 'gif', 'png', 'bmp'),
        ),
    )
);
Dave
  • 28,833
  • 23
  • 113
  • 183

1 Answers1

0

I just used this the other day. First from the way it looks, you can get either but not BOTH. I'm not sure about the uploadSettings() function not working, but I'd try using it like this:

$this->Upload->uploadSettings('Upload', 'photo', 'path',  '{ROOT}webroot{DS}uploads{DS}test{DS}ArticleData{DS}{field}');

It seems to accept arrays and non arrays but it might not be accepting arrays properly, so try it this way.

Also, as for what you're trying to accomplish, you mentioned a foreign key, but also mention the primary key. I don't believe this has support for using the foreign key, but if you're using the primary key of an upload entry as a UUID it should be fine. But if you're trying to use a foreign key, look into a combination of the path setting and rootDir setting.

tomwardiii
  • 61
  • 2