![](/img/trans.png)
[英]How to save the save the full file path in mysql table when using the upload form
[英]How to save the full path of file upload in php?
我正在使用Laravel,并且有一个上传文件的表单。 我想将该文件的完整路径保存在数据库中。 你知不知道怎么?
if($request->hasFile('alternate_add_file_path')) {
$file = $request->file('alternate_add_file_path');
$destination = 'files/';
$extension = $file->getClientOriginalExtension();
$file_name = $getCreateDate . '_' . str_replace('/','_',$M_USER_NAME) . '.' . $extension;
$file->move($destination, $file_name );
}
这是用于保存到数据库中
$M_FILE_PATH = $file_name;
我没有错误,只是保存在数据库中的文件名,而不是完整路径。
要将相对路径转换为绝对路径(服务器端),可以使用realpath
。 例如。
$fullpath = realpath($file_name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.