الكود بشكل عام كالتالي
كود PHP:
<?php
header("Content-Type: application/force-download");
header("Content-disposition: filename=file_name_here.htm");
echo "المحتوى الذي يتم تنزيله هنا";
?>
غير ال echo وحط متغير بداله بالمقال الي يتم تنزيله
----
وهذا مثال مع الشرح
كود PHP:
<?php
// التأكد من ال : PHP_SELF.php?id=xx
if (!is_numeric($REQUEST['id'])) die("يوجد خطأ"); // التوقف إذا لم يكن رقم
// إستعلام القاعدة
$query = mysql_query ("SELECT * FROM topics WHERE id='" . $REQUEST['id'] . "'") or die(mysql_error());
if (mysql_num_rows($query) > 0) { // إذا المقال موجود
$topic = mysql_fetch_array($query); // إستخراج المعلومات من الإستعلام
// لجعل المتصفح يقوم بتنزيل الملف وليس عرضه
header("Content-Type: application/force-download");
// لإخبار المتصفح باسم الملف وإمتداده
// إخترت هنا ان يكون الاسم برقم المقال :)
header("Content-disposition: filename=" . $topic['id'] . ".htm");
// محتوى الملف الذي سيتم تنزيله
echo "<html>
<head>
<title>" . $topic['title'] . "</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1256\" />
<meta name=\"Generator\" content=\"اسم موقعك هنا\" />
<meta http-equiv=\"Title\" content=\"" . $topic['title'] . "\" />
<meta http-equiv=\"Author\" content=\"" . $topic['writer'] . "\" />
</head>
<body>
" . $topic['content'] . "
</body>
</html>";
} else {
echo "المقال غير موجود";
}
?>
أو تقدر تستخدم :
كود PHP:
header("Content-Type: html/octet-stream");