-
October 8th, 2011, 19:41
#1
پسورد گذاشتن برای دانلود یک فایل
سلام دوستان.
من نیاز دارم که وقتی فردی(کاربری) روی لینک دانلود فایلم کلیک میکنه ازش یوزر پسورد بخواد.
برام مهم نیست این یوزر پسورد و تو هاست باید ست کنم یا تو برنامه نویسی.
فقط میخوام اجازه ی دانلود فایل به کسی که یوزر و پسورد نداره داده نشه.
لطفاً راهنمایی کنید.
ممنون از همه.
-
-
October 8th, 2011 19:41
# ADS
-
October 8th, 2011, 20:04
#2
عضو انجمن
پاسخ : پسورد گذاشتن برای دانلود یک فایل
اگر سرور آپاچی هست از .htaccess استفاده کنید. (روی ویندوز و IIS اصلا نمیدونم.)
و یا یک اسکریپت download بنویسید به این شکل:
کد PHP:
get the real download link from POST
save in session. prompt for username / password, validate against a database or file or loosely hard coded password
read the file
in PHP you can do via sending headers and then calling readfile.
-
تعداد تشکر ها از camelian77 به دلیل پست مفید
-
October 8th, 2011, 20:12
#3
پاسخ : پسورد گذاشتن برای دانلود یک فایل

نوشته اصلی توسط
camelian77
اگر سرور آپاچی هست از .htaccess استفاده کنید. (روی ویندوز و IIS اصلا نمیدونم.)
و یا یک اسکریپت download بنویسید به این شکل:
کد PHP:
get the real download link from POST
save in session. prompt for username / password, validate against a database or file or loosely hard coded password
read the file
in PHP you can do via sending headers and then calling readfile.
ممنون خودم با htaccess کار کردم ولی نشد.
تونستم واسه فولد پسورد بذارم ولی رو فایل نشد بازم دانلود میشد.
اینم کد پی اچ پی نیست توضیحه.
ممنونــــ-ـ_م
-
-
October 8th, 2011, 20:21
#4
عضو انجمن
پاسخ : پسورد گذاشتن برای دانلود یک فایل
خوب کد اش رو بنویسید خیلی آسونه!
توی .htaccess بگید نه تنها فولدر که فایل ها هم protected بشن.
---------- Post added at 07:21 PM ---------- Previous post was at 07:19 PM ----------
بفرمایین یه نمونه که مدت ها پیش نوشتم. الان سعی میکنم کامنت هم بگذارم:
کد PHP:
<?php get the file's link//$item=$_REQUEST['img'];
// change folders
$i = strpos ($item , "/wp-content/");
$dlPath = "./" . substr ($item, $i) ;
//********
Here you have to do some sort of user validation. you can save settings in SESSION, then display a login page which posts to itself.
//************
// proceed to download
if (file_exists($dlPath)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($dlPath)); 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($dlPath)); ob_clean(); flush(); readfile($dlPath); exit;}
?>
-
تعداد تشکر ها از camelian77 به دلیل پست مفید