du1843 2019-03-28 10:46
浏览 54
已采纳

如何在Laravel中保存修改后的图像

I'm trying to save a new photo in database which is modified, I have my javascript ( darkroomjs) for cropping photos, but the new photo doesn't save in database. I'd like to save my new photo instead of the original photo.

$profile_images = $request['profilefiles'];
$profile_images = explode(";;", $profile_images);
array_shift($profile_images);
$image = "";

foreach ($profile_images as $key => $value) {
    $image_parts = explode(";base64,", $value);
    $image_type_aux = explode("image/", $image_parts[0]);
    $image_type = $image_type_aux[1];
    $image_base64 = base64_decode($image_parts[1]);

    $destinationPath = public_path('images/model/');
    $hardPath = str_random(10) . '.' . $image_type;
    $filename = $destinationPath . $hardPath;
    file_put_contents($filename, $image_base64);

    $image = $hardPath;
}

$model->title = $request['title'];
$model->slug = Slugify::slugify($request['title']);
$model->phone = $request['phone'];
$model->external_link = $request['external_link'];
$model->email = $request['email'];
$model->description = $request['description'];
$model->category = $request['category'];
$model->instagram = $request['instagram'];
$model->category_id = $request['category_id'];
$model->badges_id = $request['badges_id'];
$model->height = $request['height'];
$model->boost = $request['boost'];
$model->waist = $request['waist'];
$model->hips = $request['hips'];
$model->shoes = $request['shoes'];
$model->hair = $request['hair'];
$model->eyes = $request['eyes'];
$model->dress = $request['dress'];
$model->publish = $publish;
$model->age = date('Y-m-d', strtotime($request['dob']));
$model->metatitle = $request['title'];
$model->metadescription = substr(strip_tags($request['description']), 0, 160);

if ($image != "") {
    var_dump($image);
    $model->image = $image;
}
$model->upload_pdf = $upload_pdf;
$model->save();

  • 写回答

2条回答 默认 最新

  • doumeinuoye81969 2019-03-28 12:14
    关注

    enter image description here

    Above image shows callback to get edited image.

    1) You can save this file somewhere in temp folder at server by making ajax call to server.

    2) During you save other fields(POST request). You can simply move file from temp folder to your images folder and file name into DB.

    Ref : https://github.com/MattKetmo/darkroomjs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?