morteza5691
پنج شنبه 20 فروردین 1394, 20:02 عصر
سلام خدمت اساتید محترم
من برای ارسال فایل از سرور به کاربر (دانلود) از تابع readfile استفاده کردم. ولی متاسفانه باعث شده تابع setcookie عمل نکنه!!!!:اشتباه:
وقتی readfile رو برمیدارم کوکی ثبت میشه.
به نظر شما باید چیکار کنم؟؟ :متفکر:
نمونه کد :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Read File</title>
</head>
<body>
<?php
$filename = "123.mp4";
$filesize = filesize($filename);
if($_POST['download'] == true) {
if(setcookie("morteza", "ReadFile", time()+86400,"/")) {
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.$filesize);
ob_clean();
flush();
readfile($filename);
}
else {
echo "False";
}
}
echo $_COOKIE["morteza"];
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="download" value="true" />
<input type="submit" name="submit" value="Download!" />
</form>
</body>
</html>
من برای ارسال فایل از سرور به کاربر (دانلود) از تابع readfile استفاده کردم. ولی متاسفانه باعث شده تابع setcookie عمل نکنه!!!!:اشتباه:
وقتی readfile رو برمیدارم کوکی ثبت میشه.
به نظر شما باید چیکار کنم؟؟ :متفکر:
نمونه کد :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Read File</title>
</head>
<body>
<?php
$filename = "123.mp4";
$filesize = filesize($filename);
if($_POST['download'] == true) {
if(setcookie("morteza", "ReadFile", time()+86400,"/")) {
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.$filesize);
ob_clean();
flush();
readfile($filename);
}
else {
echo "False";
}
}
echo $_COOKIE["morteza"];
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="download" value="true" />
<input type="submit" name="submit" value="Download!" />
</form>
</body>
</html>