简体   繁体   中英

how to check if an image exists laravel

I am posting data from iOS with some parameters. I have converted image into bytes and uploading it to server. The parameter's data is saving successfully. But i am unable to check if there appears any image or not. Is there any method or something to check that if there exists any image in the request? Below is the code written for storing data. anything else is working fine except image and i am sure. Bytes are sent successfully by iOS app. I am unable to handle or extract image from the request.

public function createIdea(Request $request) {
    $filename = '';
    if ($request->hasFile('idea_image')) {
        $filename = $request->file('idea_image')->getClientOriginalName();
        $moveImage = $request->file('idea_image')->move('images', $filename);
    }
    $idea = new Idea();
    $idea->idea_info = $request->input('idea_title');
    $idea->idea_info = $request->input('idea_info');
    $idea->idea_image = "images/".$filename;
    $idea->idea_location = $request->input('idea_location');
    $idea->idea_description = $request->input('idea_description');
    $idea->idea_description = $request->input('selection');
    $idea->user_id = \Auth::id();
    dd($idea);
    $idea->save();
    $ideaId = $idea->id;
    if ( ! $idea->id ) {
        $statusCode =404;
        response()->json(array('Status:' => 'Idea Creation FAILED'),$statusCode);
    }else{
        $response = $idea->toJson();
        $statusCode =200;
        return response()->json(array('Status:' => 'Idea Created Successfully', 'ideaId' => $ideaId),$statusCode);
    }
}

Simple.

if (File::exists($myfile)) {
    echo "Yup. It exists.";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM