التطور للوب بواسطةmysql!PHP - ويلينغ — الصفحة ٧٨٤

<? توليد مستندات ذات طابع شخصي في تنسيق المستند المحمول (PDF) الفصل 30 السرد (330) rtf.php - نص برمجي لإنتاج شهادة RTF ذات طابع شخصي // check we have the parameters we need if( !$name || !$score ) { echo "<h1>Error:</h1>This page was called incorrectly"; } else { //generate the headers to help a browser choose the correct application header( "Content -type: application/msword" ); header("Content -Disposition: inline, filename=cert.rtf"); $date = date( "F d, Y" ); // open our template file $filename = "PHPCertificati on.rtf"; $fp = fopen($filename, "r" ); //read our template into a variable $output = fread( $fp, filesize( $filename ) ); fclose($fp); // replace the place holders in the template with our data $output $output $output $output = = = = str_replace("<<NAME>>", strtoupper( $name), $output); str_replace("<<Name>>", $name, $output); str_replace("<<score>>", $score, $output); str_replace("<<mm/dd/yyyy>>", $date, $output); // send the generated document to the browser echo $output; } ?> نحدد النوع MIME للملف الذي ننتجه باستعمال الدالة ()header التابعة لـ PHP لإرسال الرأس HTTP الملائم كالتالي: header("Content-type: application/msword" ); header("Content-Disposition: inline, filename=cert.rtf"); الرأس الأول يبلغ المستعرض أننا نرسل ملف مايكروسوفت وورد (ليس صحيحاً بشكل المساعد الأكثر رواجاً لفتح الملف RTF). البرنامج لكنه صارم، هو .cert.rtf الرأس الثاني يبلغ المستعرض بأن يعرض محتويات الملف تلقائياً، وأن إسمه المقترح هذا هو إسم الملف الافتراضي الذي سيراه المستخدم إذا حاول حفظ الملف من ضمن مستعرضه. 800
ص٧٨٤

نص مستخرج آليًا من الصورة، وقد يقع فيه خطأ.