skipperbent / simple-php-router

Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
647 stars 121 forks source link

Unable to handle url-encoded and form-data request #685

Open ItzfeminisceBEnd opened 11 months ago

ItzfeminisceBEnd commented 11 months ago

The input()->() and request()-> will not catch file contents in request.

I have tried every possible means to handle uploaded files but it's not present in the request body.

I set content type to application/json, it won't. I also set it to url-encoded, even form-data. Neither was it able to handle.

Please is there some other way to get these content?

DeveloperMarius commented 11 months ago

Hey,

can you share your request body and headers with us?

~ Marius

ItzfeminisceBEnd commented 11 months ago

Request Header: Authorization: Bearer <token> User-Agent: PostmanRuntime/7.34.0 Accept: / Cache-Control: no-cache Postman-Token: 5c0fe45e-0db4-44dd-b83b-0250c95fe87f Host: localhost Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Type: multipart/form-data; boundary=--------------------------191050165857157560352247 Cookie: PHPSESSID=hhgbb05m0eklch792b435rjutt Content-Length: 19554622

Request Body: post_text: "Hello world" post_img: <file>

MY CODE:

public function store() {
    try {
      $validate = purify(input()->all());
      $req = $validate([
        "post_text" => 'required',
        "post_img" => 'optional',
      ]);
      //input()->file('post_img') // Always null
      // $req->post_text == input()->find("post_text)
      // $req->post_img == input()->file(post-img) // Butt this is always null
      return Post::getInstance()->store($req->post_text, input()->file("post_img", null));
    }catch(\Exception $e) {
      Logger::system($e->getMessage());
      return json_response(["message" => $e->getMessage()]);
    }
  }