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条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效