我想上传一张图片并在需要时从数据库中检索。我的代码可以完美地上传图片,但它的路径没有保存在数据库中。在数据库中,它显示Null。下面是我的代码:

    if ($request->hasFile('profilePic')) {
        $file = array('profilePic' => Input::file('profilePic'));
        $destinationPath = 'img/'; // upload path
        $extension = Input::file('profilePic')->getClientOriginalExtension();
        $fileName = rand(11111,99999).'.'.$extension; // renaming image
        Input::file('profilePic')->move($destinationPath, $fileName);
    }else{
        echo "Please Upload Your Profile Image!";
    }
    $profile->save();

我的问题是:
如何将图像路径保存到数据库中?
如何从数据库中检索图像?
更新:profile.php
class Profile extends Model
{
    protected $table = "profiles";
    public $fillable = ["firstName","lastName","middleName","DOB","gender","featuredProfile","email","phone","summary","profilePic"];
}

最佳答案

在你的代码中应该有如下内容:

$profile->profilePic = $fileName;

&那么
$profile->save();

10-08 00:47