圖片上的臨時文件夾,以便上傳:
#Get the path to the uploaded img
$filePath = Input::file('imgInp')->getRealPath();
$fileName = Input::file('imgInp')->getClientOriginalName();
$extension = Input::file('imgInp')->getClientOriginalExtension();
#Lets add the extension to the file name
$fileNameWithExtension = $fileName . '.' . $extension;
#Create the folder img/uploaded on your public folder!
$destination = public_path('img/uploaded/' . $fileNameWithExtension);
#Copy the img to your desired destination
#copy ($filePath, $destination);
#Instead of the copy function you can use this laravel function
Input::file('imgInp')->move($destination);
#Save on database the path to your img
$admin = Admin::find(25);
$admin->picture = $destination;
$admin->update();
我希望它的作品。沒試過
然後,如果你想展示你的形象只是做到以下幾點:
$admin = Admin::find(25);
#Pass the variable to your view and them, if you use blade templating system:
<img src="{{asset($admin->picture)}}">
#If you are not using blade do it this way
<img src="<?php echo asset($admin->picture); ?>">
任何錯誤/異常? –
@André我已經在問題中說過我已經嘗試了' - > save()',但沒有任何內容保存到我的數據庫中 –
您不應該在數據庫中存儲任何作爲base64的圖像。只需將img保存到資產文件夾並將路徑存儲到img即可。 –