I'm trying to automatically fetch some details of a file that has been uploaded, however there are two slight issues. I can't manage get the file name to show up without an extension, and the absolute path turns out wonky such as C:\Users\Tyrx\Desktop\php part 2\FileDepository - back to\public/assets/7ofmMvm.jpg.
Is there any chance somebody could guide me in the right direction? Here's the two snippets of code for generating the file name and file path.
File Name (for example, this results in 7ofmMvm.jpg instead of 7ofmMvm)
$filelist->name = $this->request->file('asset')->getClientOriginalName();
File Path
$fullfilepath = $destinationPath . $filelist->name;
$filelist->file_path = $fullfilepath;
The full code of the function
public function store()
{
$filelist = new Filelist($this->request->all());
//store file details
$filelist->name = $this->request->file('asset')->getClientOriginalName();
$filelist->file_type = $this->request->file('asset')->getClientOriginalExtension();
$filelist->file_size = filesize($this->request->file('asset'));
$filelist->uploader_name = Auth::user()->email;
$filelist->save();
// Save uploaded file
if ($this->request->hasFile('asset') && $this->request->file('asset')->isValid()) {
$destinationPath = public_path() . '/assets/';
$fileName = $filelist->id . '.' . $this->request->file('asset')->guessClientExtension();
$this->request->file('asset')->move($destinationPath, $fileName);
}
$fullfilepath = $destinationPath . $filelist->name;
$filelist->file_path = $fullfilepath;
$filelist->save();
return redirect('filelists');
}
if ($this->request->hasFile('asset') && $this->request->file('asset')->isValid()) {
$destinationPath = public_path() . '/assets/';
$fileName = $filelist->id . '.' . $this->request->file('asset')->guessClientExtension();
$this->request->file('asset')->move($destinationPath, $fileName);
}
$fullfilepath = $destinationPath . $filelist->name;
$filelist->file_path = $fullfilepath;
$filelist->save();