![](/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.