Reputation: 102
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?
Upvotes: 0
Views: 289
Reputation: 9693
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.
Upvotes: 1
Reputation: 3244
If I were you, I would save my file somewhere after upload, then it will be easy to save path so that you can download the files in another program:
public function savePath($file)
{
$file = Input::file('fileuploader');
$destinationPath = ‘storage/uploads/yourFolder’;
$file->move($destinationPath,$file->getClientOriginalName());
Db::table('auto_quotes')->where('quote_no', $quote->quote_no)->update(['path' => $destinationPath]);
}
It’s up to you if you need to save $destinationPath
or $destinationPath.$file->getClientOriginalName()
PS: Store your files in storage
folder, if not you may have permission issue
Upvotes: 0