Sunday 15 August 2010

php - attach file as multipart/form-data content-type - Laravel -



php - attach file as multipart/form-data content-type - Laravel -

i using freshdesk api ticketing system. when trying send attachment, stated should sent multipart/form-data content-type. explain how done?! how sending attachments:

$json = json_encode( array( "helpdesk_note" => array( "body" => input::get('reply'), "user_id" => $requester_id, "attachments" => input::get('photo'), "private" => true ) ) );

i don't know how you're querying api in case you're using curl, set appropriate header:

curl_setopt($ch , curl_httpheader , "content-type: multipart/form-data" );

personally recommend guzzle has clean , straightforward api. in guzzle can modify headers in more oo-way. there several ways accomplish task. on possible approach be:

$client = new guzzlehttp\client(); $request = $client->createrequest('post', 'https://url.com/to/post/to'); $request->setheader('content-type', 'multipart/form-data'); // set info need $response = $client->send($request); var_dump($response);

guzzle btw, piece of cake integrate laravel. require in composer.json , you're go!

php multipartform-data

No comments:

Post a Comment