【发布时间】:2017-04-07 12:37:36
【问题描述】:
我正在使用 laravel 5.4,我正在尝试替换我的请求中的 imagePath 字段(重命名上传的图片)。
解释:
提交表单时,请求字段(request->imagePath)包含上传图像的临时位置,我将该 tmp 图像移动到一个目录,同时更改其名称($name)。所以现在 request->imagePath 仍然有旧的 tmp 图像位置,我想更改 request->imagePath 值以拥有新位置,然后创建用户。
像这样
if($request->hasFile('imagePath'))
{
$file = Input::file('imagePath');
$name = $request->name. '-'.$request->mobile_no.'.'.$file->getClientOriginalExtension();
echo $name."<br>";
//tried this didn't work
//$request->imagePath = $name;
$file->move(public_path().'/images/collectors', $name);
$request->merge(array('imagePath' => $name));
echo $request->imagePath."<br>";
}
但它不起作用,这是输出
mahela-7829899075.jpg
C:\xampp\tmp\php286A.tmp
请帮忙
【问题讨论】:
-
把它当成一个普通数组就行了:
$request['imagePath'] = $name,不是吗? -
@Jean-PhilippeMurray 也尝试过,但它仍然没有改变任何东西
标签: php laravel replace laravel-5.4