Serverga fayllarni yuklash. Reja


Download 261.38 Kb.
bet6/7
Sana07.04.2023
Hajmi261.38 Kb.
#1340623
1   2   3   4   5   6   7
Bog'liq
24 Serverga fayllarni yuklash

Index.php – asosiy yuqoridagi php fayl
// xatolar haqida habar berish:
error_reporting(E_ALL^E_NOTICE);
// Baza bilan bog`lash:
require 'connect.php';
$extension='';
$files_array = array();
/* files papkasidagi barcha fayllarni o`qish: */
$dir_handle = @opendir($directory) or die("files papkasi topilmadi fayl yo`q!");
while ($file = readdir($dir_handle))
{
/* Fayllar identifikatsiyasidan o'tmadingiz */
if($file{0}=='.') continue;
/* explode() uchun end () funktsiyasi oxirgi massiv elementini ko'rsatadi: */
$extension = strtolower(end(explode('.',$file)));
/* Php fayllarga o'tish */
if($extension == 'php') continue;
$files_array[]=$file;
}
/* Alifbo tartibda fayllarni tartiblashtirish */
sort($files_array,SORT_STRING);
$file_downloads=array();
$result = mysql_query("SELECT * FROM download_manager");
if(mysql_num_rows($result))
while($row=mysql_fetch_assoc($result))
{
/* Qator muhim, $ file_downloads fayl nomi bo'ladi
va yuklashlar sonini o'z ichiga oladi */
$file_downloads[$row['filename']]=$row['downloads'];
}
Biz mysql_query () yordamida download_manager baza jadvalida barcha qatorlarni tanlaydi e'tibor bering, va yuklashlar soni bir kalit sifatida fayl nomi bilan array $ file_downloads filename-jadvalga fayl nomini qo'shing. Misol: files papkaga [ 'kitob.zip'] faylini ko`chiring va baza jadvaliga $ file_downloads yozing.
Agar elementlar ro'yxatini chiqaradi kodni ko'rasiz Quyida:
index.php – asasiy o`rtadagi php fayl
foreach($files_array as $key=>$val)
{
echo '
  • '.$val.'
    '.(int)$file_downloads[$val].' Yuklash
  • ';
    }
    Hamma narsa foreach halqa array $ files_array yordamida shunchaki amalga oshiriladi. Shundan so'ng, barcha fayllar ko`rsatiladi ko'rsatiladi. Agar fayl files papkadagi fayllar bilan filename-baza jadvaliga mos tushmasa unda xatolik sodir bo`ladi.
    Endi qanday qilib faylni ko`chirib olishni va kuzatish (sonda) da batafsil ko'rib chiqaylik.
    download.php fayli quyidagi ko`rishishda bo`ladi.
    // Xato nazorat qilish:
    error_reporting(E_ALL^E_NOTICE);
    // Fayli baza bilan ulanish yoqish:
    require('connect.php');
    if(!$_GET['file']) error('parametrlar mos tushmadi!');
    if($_GET['file']{0}=='.') error('filda xato!');
    if(file_exists($directory.'/'.$_GET['file']))
    {
    /* saytdan foydalanuvchi mehmon, faylni sichqoncha bilan bosib yuklab olgan bo`lsa, yuklab olishni hisoblaudi: */
    if(!is_bot())
    mysql_query(" INSERT INTO download_manager SET filename='".mysql_real_escape_string($_GET['file'])."'
    ON DUPLICATE KEY UPDATE downloads=downloads+1");
    header("Location: ".$directory."/".$_GET['file']);
    exit;
    }
    else error("fayl papkada yo`q!");
    /* xato funktsiyasi yordamchisi:*/
    function error($str)
    {
    die($str);
    }
    function is_bot()
    {
    /*Bu funksiya ishlash jarayonida kuzatiladi */
    $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
    "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
    "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
    "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
    "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
    "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
    "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
    "Butterfly","Twitturls","Me.dium","Twiceler");
    foreach($botlist as $bot)
    {
    if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
    return true;
    }
    return false;
    }
    Bu ma'lumotlar bazasi bir qator fayllarni yulashni is_bot () tekshirish orqali downloads-baza jadvaliga sonni hisoblab boradi.

    Download 261.38 Kb.

    Do'stlaringiz bilan baham:
    1   2   3   4   5   6   7




    Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
    ma'muriyatiga murojaat qiling