【发布时间】:2015-10-04 00:06:16
【问题描述】:
我正在尝试自动获取已上传文件的一些详细信息,但是有两个小问题。我无法在没有扩展名的情况下显示文件名,并且绝对路径结果很奇怪,例如 C:\Users\Tyrx\Desktop\php part 2\FileDepository - back to\public/assets/ 7ofmMvm.jpg.
有没有人可以引导我朝着正确的方向前进?这是生成文件名和文件路径的两个sn-ps代码。
文件名(例如,这会导致 7ofmMvm.jpg 而不是 7ofmMvm)
$filelist->name = $this->request->file('asset')->getClientOriginalName();
文件路径
$fullfilepath = $destinationPath . $filelist->name;
$filelist->file_path = $fullfilepath;
函数的完整代码
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();
【问题讨论】: