Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图像存储,但在laravel API中未显示正确路径_Laravel_Laravel 5_Laravel 4_Postman_Laravel Api - Fatal编程技术网

图像存储,但在laravel API中未显示正确路径

图像存储,但在laravel API中未显示正确路径,laravel,laravel-5,laravel-4,postman,laravel-api,Laravel,Laravel 5,Laravel 4,Postman,Laravel Api,如何在数据库中存储实际路径,如何在API中获取图像? 这是postman中API的输出 这是显示图像存储路径的数据库,但它是错误的 公共函数存储(请求$Request) { $event=$request->all(); 如果($request->hasFile('file')){ $destinationPath=public_path()。/public/img/; $file=$request->file; $fileName=time().。$file->clientExtensio

如何在数据库中存储实际路径,如何在API中获取图像? 这是postman中API的输出

这是显示图像存储路径的数据库,但它是错误的

公共函数存储(请求$Request)
{
$event=$request->all();
如果($request->hasFile('file')){
$destinationPath=public_path()。/public/img/;
$file=$request->file;
$fileName=time().。$file->clientExtension();
$file->move($destinationPath,$fileName);
$input['e_image']=$fileName;
}
//$return['success']=true,
//$return['data']=$event,
//$return['msg']=“这是消息”;
$success['status']=true;
$success['data']=[$event];
$success['message']=“事件创建成功!”;
//$success['event']=$event;
return response()->json($success);

}
请尝试此操作,并使用唯一的图像名称将图像存储在适当的项目目录中

$img=$request->profile\u image;
$old\u path=public\u path()。“/public/img/”;
$image_parts=分解($base64,$img);
$image_type_aux=explode(“image/”,$image_parts[0]);
$image_type=$image_type_aux[1];
$image_base64=base64_decode($image_parts[1]);
$filename=uniqid()。巴布亚新几内亚';
$file=$old\u路径$文件名;
文件内容($file$image\u base64);
如果(文件存在(公共路径('/public/img/'.$filename))){
//移动图像
$new_path=public_path()。“/public/img/newimages/”;
如果(!is_dir($new_path)){
mkdir($new_path,0777,TRUE);
}
$move=File::move($old_path.$filename,$new_path.$filename);
}
//在数据库上传图像
$modalObj=新表();
$modalObj->updateById(\Session::get('table')->id[
“profile_photo”=>$filename,
]);

return response()->json(['code'=>'1','message'=>'图像上传成功!!!','data'=>['imageName'=>url('/public/img/newimages/'.$filename)])$file=new YOURMODELNAME();请在此代码行中输入您的型号名称

public function store(Request $request)
     {
        $input = $request->all();
        $rules = array(
            'e_image' => 'required|mimes:jpeg,png,jpg,doc,docx,pdf,mp4,mov,ogg,qt',
       'e_group' => required,
       'e_invite'=>required,
        );
        $validator = Validator::make($input, $rules);
        if ($validator->fails()) {
            $arr = array("status" => 400, "message" => $validator->errors()->first(), "data" => array());
        } else {
            try {
                $file = $request->file('e_image');
                $input['e_image'] = time() . '.' . $file->getClientOriginalExtension();
                $destinationPath = public_path('/img/');
                $file->move($destinationPath, $input['e_image']);




                $file = new YOURMODELNAME();





                $file->e_image = $input['e_image'];
                $file->e_group = $input['e_group'];
                $file->e_invite = $input['e_invite'];
                $file->save();
                $file->e_image = url('public/img/' . $file->e_image);


                $arr = array("status" => 200, "message" => "file upload Successfully", "data" => $file);
            } catch (\Exception $ex) {
                if (isset($ex->errorInfo[2])) {
                    $msg = $ex->errorInfo[2];
                } else {
                    $msg = $ex->getMessage();
                }
                $arr = array("status" => 400, "message" => $msg, "data" => array());
            }
        }
        return \Response::json($arr);
    }

DB中的代码存储数据在哪里?在存储函数中..您可以检查问题-@shaileshladumory您必须将图像上载到存储文件夹中,然后将文件名存储在数据库中,在上载图像后检索到该文件名。在API中传递数据时,使用图像名称将URL链接附加到存储中。你可以在这里找到更好的图片上传代码块。对不起,实际上我不懂你的代码-@PHP GeekHe已经存储了一个唯一的图像名称<代码>$fileName=time()$文件->客户端扩展()这行用扩展名创建唯一时间,不是吗?是的-@diliphirapara我只懂我的代码,你能检查我代码中的错误吗?-@PHP Geek