这是代码:
$fileName = <something to code here>; $path = $request->file('the_file')->storeAs('the_path', $fileName, 'public'); return $path;
我想要实现的是,当文件上传到数据库时,我希望文件以这种名称“product-code_product-name.jpg”保存,而不是使用它的原始名称。
我尝试过:
$fileName = time() . $request->file('the_file')->getClientOriginalName()
感谢您回答我的问题,并为我糟糕的英语感到抱歉。
// Combine the sanitized product code and product name
$customFileName = $productCode . "_" . $productName . ".jpg";
// Replace any spaces with underscores
$customFileName = str_replace(" ", "_", $customFileName);
// Save the file with the custom filename
$path = $request->file('the_file')->storeAs('the_path', $customFileName, 'public');