This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

pwtan14262
pwtan14262

Hi all,

I needed help on getting the filepath of a uploaded file for backend. The file reside in system file eg. storage/app/uploads/public/56e/f51/34b/56ef5134b1b47739660276.csv I'm getting the file path in Model file. I have looked through the forum but none get me result. The following are my code

public $attachOne = [
     'file' => ['System\Models\File', 'public' => false]
];

public function afterSave(){ $filePath = $Model->file->getPath(); Log::info($filePath); }

Last updated

philipptempel
philipptempel

As per the docs getPath() gets you the full URL of an uploaded file while getLocalPath() gets you the local path of the file i.e., an absolute file path on the local filesystem. If I understand your question, you would want to use getLocalPath().

pwtan14262
pwtan14262

Hi philipptempel,

Thanks for your reply. I have already tried that. It produces the error "Undefined variable:model" Perhaps you have other suggestion? Thanks

AlexeiKo
AlexeiKo

change $model to $this and it will work

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.