PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : پسورد گذاشتن برای دانلود یک فایل



delhamid
October 8th, 2011, 19:41
سلام دوستان.

من نیاز دارم که وقتی فردی(کاربری) روی لینک دانلود فایلم کلیک میکنه ازش یوزر پسورد بخواد.

برام مهم نیست این یوزر پسورد و تو هاست باید ست کنم یا تو برنامه نویسی.

فقط میخوام اجازه ی دانلود فایل به کسی که یوزر و پسورد نداره داده نشه.

لطفاً راهنمایی کنید.

ممنون از همه.

camelian77
October 8th, 2011, 20:04
اگر سرور آپاچی هست از .htaccess استفاده کنید. (روی ویندوز و IIS اصلا نمی‌دونم.)

و یا یک اسکریپت download بنویسید به این شکل:




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.

delhamid
October 8th, 2011, 20:12
اگر سرور آپاچی هست از .htaccess استفاده کنید. (روی ویندوز و IIS اصلا نمی‌دونم.)

و یا یک اسکریپت download بنویسید به این شکل:




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 کار کردم ولی نشد.
تونستم واسه فولد پسورد بذارم ولی رو فایل نشد بازم دانلود میشد.
اینم کد پی اچ پی نیست توضیحه.

ممنونــــ-ـ_م

camelian77
October 8th, 2011, 20:21
خوب کد اش رو بنویسید خیلی آسونه!

توی .htaccess بگید نه تنها فولدر که فایل ها هم protected بشن.

---------- Post added at 07:21 PM ---------- Previous post was at 07:19 PM ----------

بفرمایین یه نمونه که مدت ها پیش نوشتم. الان سعی می‌کنم کامنت هم بگذارم:


<?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;}
?>