Sending Strings as Files with CakePHP server response
With CakePHP it is quite easy to send any string as a subfile. As an example below is the creation of an ICS subfile (for a calendar invites)
public function sendIcs()
{
$icsString = $this->Calendars->generateIcs();
$response = $this->response;
// Inject string content into response body $response = $response->withStringBody($icsString);
$response = $response->withType('ics');
// Optionally force file download $response = $response->withDownload('filename_for_download.ics');
// Return response object to prevent controller from trying to render // a view. return $response; }
Example above is from official CakePHP book.
💜 Thank You!
URLs
- You can also check my status page or micro.blog if you want know what I'm doing
Projects
- I hosing my projects on GitHub
- I'm currently working on Api Client for the omg lol service.
Don't miss what's next. Subscribe to May Meow: