我想在db中存储上传的用户图像路径。这是我在控制器中的代码,
$file = Input::file('pic');
$img = Image::make($file);
Response::make($img->encode('jpeg'));
$filepath = $file->getPathName();
但上面的代码结果, 错误的路径,如 C:\ xampp \ tmp \ phpA0C8.tmp 我已经从我的laravel公共文件夹上传了图片。我尝试了很多代码,但他们并没有我怎么解决这个问题?有人可以帮忙吗?
答案 0 :(得分:0)
您必须使用文件名定义路径。
$FileName = Input::file('pic')->getClientOriginalName();
$FileDestinationPath = public_path('') .'/folder-name-in-public-folder/'.$FileName;
或者你可以使用商店方法获得它
$path = Input::file('pic')->store('folder-name');
return $path;
答案 1 :(得分:0)
答案 2 :(得分:0)
使用laravel文件存储方法和hashname
m = 0
For Each htmlele1 In doc.getElementsByClassName("results")
m = m + 1
companyname = htmlele1.getElementsByTagName("h2")
Address = htmlele1.getElementsByTagName("span")
If Address.getAttribute("itemprop") = "Address" Then
Cells(i, (m * 4 + 2)).Value = companyname.innerText + "," + Address.innerText
End If
Teliphone = htmlele1.getElementsByClassName("nolink")
If Teliphone.getAttribute("itemprop") = "telephone" Then
Cells(i, (m * 4 + 3)).Value = Teliphone.innerText
End If
no_of_property = htmlele1.getElementsByClassName("agents-stats-l")
If InStr(no_of_property.innerText, "Residential for sale") <> 0 Then
Cells(i, (m * 4 + 4)).Value = Replace(no_of_property.innerText, "Residential for sale:", "")
Else
Cells(i, (m * 4 + 4)).Value = 0
End If
Sale_price = htmlele1.getElementsByClassName("agents-stats-c")
If InStr(Sale_price.innerText, "Avg. asking price") <> 0 Then
Cells(i, (m * 4 + 5)).Value = Replace(Sale_price.innerText, "Avg. asking price: ", "")
Else
Cells(i, (m * 4 + 5)).Value = 0
End If
Next
//配置/ filesystems.php
public function fileUPload(Request $request){
$file = $request->file('pic');
$dir = '/my_images/';
$file->store($dir, 'public_path'); //store images
echo $filePath= $dir . $file->hashName();
}