I have a php class I use to generate Ical data. For now I just generate an ical file but I'd like to avoid creating it and just treat my ical data string to use it as an email attachment I could send. Is there a way in PHP to turn a string into a file without creating it? just treating it like a file?
public function sendInviteMail ($mailTutor, $mailBeneficiary, $meetingDate, $meetingEndDate, $meetingName, $meeting_location, $cancel, $UID){
$meetingStamp = strtotime($meetingDate . " UTC");
$meetingEndStamp = strtotime($meetingEndDate . " UTC");
$dtstart= gmdate("Ymd\THis\Z",$meetingStamp);
$dtend= gmdate("Ymd\THis\Z",$meetingEndStamp);
$todaystamp = gmdate("Ymd\THis\Z");
//Create unique identifier @todo Changer la méthode de creation récupérer l'uid en base ou le reconstruire si possible
$cal_uid = $UID;
$ical = "BEGIN:VCALENDAR
".
"VERSION:2.0
";
if($cancel){
$ical.="METHOD:CANCEL
";
}
$ical .= "BEGIN:VEVENT
".
"UID:".$cal_uid."
".
"ORGANIZER;CN=Test:".$mailTutor."
".
"DTSTART:".$dtstart."
".
"DTEND:".$dtend."
".
"DTSTAMP:".$todaystamp."
".
"DESCRIPTION:".$meetingName."
".
"SUMMARY:".$meetingName."
".
"LOCATION:".$meeting_location."
".
"END:VEVENT
".
"END:VCALENDAR";
$ics_file = fopen('MYPATH/myicsfile.ics', "w+");
fwrite($ics_file, $ical);
fclose($ics_file);
$messagetobesent = Swift_Message::newInstance('Appointment Subject')
->setFrom(array('admin@noreply.com' => 'John Doe'))
->setTo(array($mailTutor, $mailBeneficiary))
->setBody($message)
;
$swiftAttachment = Swift_Attachment::fromPath($icsfile);
$messagetobesent->attach($swiftAttachment);
$this->get('mailer')->send($messagetobesent);
}
I would like to get rid of the fopen fwrite fclose part and attach a file that only exists in memory but not on the hard drive.