Matt McManis
Matt McManis

Reputation: 4675

October CMS How to Change Path of File Upload?

I'm using October CMS.

I made a simple front-end File Upload Plugin. I have a Model and Component.

upload form

In Model Uploader.php I use

public $attachOne = [
    'videofile' => 'System\Models\File'
];

And in the Component

public function onUpload(){
    $uploader = new Uploader();
    $uploader->videofile = Input::file('videofile');
    $uploader->save();
    Flash::success('File Uploaded');
    return Redirect::back();
}

By default, Uploads go to

/storage/app/uploads/public/random-dir/random-name.mp4

The CMS is giving the files a random directory and name.

But backend Media Uploads go to

/storage/app/media/filename.mp4

The File name is preserved.

How do I make the files upload to /media instead of /uploads/public?

Or is it possible to define a folder and filename instead of random in /uploads/public?

Upvotes: 1

Views: 2638

Answers (1)

dragontree
dragontree

Reputation: 1799

You can move the file before attaching it to the Uploader model:

Input::file('videofile')->move($destinationPath, $fileName);

You can get the original filename like this

$name = Input::file('videofile')->getClientOriginalName();

Upvotes: 1

Related Questions