Ad

OctoberCMS GetPath For Multiple Files

- 1 answer

I have a problem which I cannot seem to resolve, I am uploading multiple files on the frontend but I need to get the paths of these files so that I can download the files in another program.

My model looks like this:

public $attachMany = [
    'fileuploader' => 'System\Models\File'
];

Then I tried something silly like this on the component:

$quote->fileuploader = Input::file('fileuploader');

foreach ($quote->fileuploader as $file) {
            Db::table('auto_quotes')->where('quote_no', $quote->quote_no)->update(['path' => $file->fileuploader->getPath()]);
        }

But I get a result of getPath = null.

Anyone perhaps know how I should go about this?

Ad

Answer

hmm may be your code require little bit correction,

also we need to save $quote to use its files i guess.

$quote->fileuploader = Input::file('fileuploader');

// save it before using
$quote->save();

foreach ($quote->fileuploader as $file) {
    Db::table('auto_quotes')
      ->where('quote_no', $quote->quote_no)
      ->update(['path' => $file->getPath()]); // <- correction
}

instead of using $file->fileuploader->getPath() just use $file->getPath()

as we are already looping through $quote->fileuploader and each file will be $file so we don't need to use $file->fileuploader we can use $file itself

if still getting issue please comment.

Ad
source: stackoverflow.com
Ad