• 08-04-2010, 14:46:00
    #1
    Üyeliği durduruldu
    Alıntı
    <?php
    class Browse {
    var $folder= '.';
    var $file;
    var $files = array();
    var $handle;
    var $ext;
    var $invalid_files;

    public function BrowseAJAX($inputValue, $fieldID) {
    return $this->dirList($fieldID, $inputValue);
    }
    //separate each folder with spaces or hyphens
    public function hyphens($dir) {
    $hyphens_amount = array();
    $count = explode('/',$dir);
    foreach ($count as $each) {
    $hyphens_amount[] = '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp';
    }
    return implode($hyphens_amount);
    }
    //check extension
    public function valid_extension($filename) {
    $this->ext = substr (strrchr ($filename, "."), 1);
    return array_search ($this->ext, $this->invalid_files);

    }
    //get mime type
    public function get_mime_type($filename) {
    if (!function_exists ('mime_content_type')) {
    function mime_content_type ( $f ) {
    return exec ( trim( 'file -bi ' . escapeshellarg ( $f ) ) ) ;
    }
    }
    $type = mime_content_type($filename);
    return $type;
    }
    //format file size
    public function file_size($file) {
    $size = filesize($file);
    if (strlen($size) <= 9 && strlen($size) >= 7) {
    $size = number_format($size / 1048576,1);
    return ''.$size.'MB';
    } elseif (strlen($size) >= 10) {
    $size = number_format($size / 1073741824,1);
    return ''.$size.'GB';
    } else {
    $size = number_format($size / 1024,1);
    return ''.$size.'KB';
    }
    }
    function htmlspecialchars_decode($text) {
    return strtr($text, array_flip(get_html_translation_table(HTML_SPECIAL CHARS)));
    }
    //List all in directory

    private function dirList($folder,$state) {
    $temp = '';

    if ($this->handle = opendir($folder)) {
    while (false !== ($this->file = readdir($this->handle))) {
    array_push($this->files,$this->file);

    }

    foreach ($this->files as $i) {

    $dir = $folder.$i;

    if (is_dir($dir) && $i!='.' && $i!='..') {
    $temp .= '
    <b><span id="'.$dir.'/" title="open" onclick=\'browse(this.title, this.id);document.getElementById("'.$dir.'/Info").innerHTML = "";\' />
    '.$this->hyphens($dir).'
    <img border="0" id="image'.$dir.'/" src="../img/folder.gif">
    <a href="javascript:void(0)">'.$i.'</a>
    </span>
    </b><br>
    <span id="'.$dir.'/Info" class=""></span>
    ';
    }
    elseif ($i=='.' || $i=='..' || $this->valid_extension($i)) {}
    else {

    $temp .= '

    <span onmouseover="document.getElementById(\'stat'.$dir. '\').className = \'show\';" onmouseout="document.getElementById(\'stat'.$dir.' \').className = \'hidden\';" name='.$i.'" />
    '.$this->hyphens($dir).'
    <img border="0" src="../img/generic.gif">
    <a href="'.$dir.'">'.$i.'</a>
    <span id="stat'.$dir.'" class="hidden" name='.$i.'" />

    &nbsp&nbsp&nbspBoyut- '.$this->file_size($dir).'</span>
    </span><br>
    ';
    }
    }
    closedir($this->handle);
    }
    return htmlentities($temp);
    }


    }
    ?>
    Burda sort fonksiyonunu kullanarak,tüm klasor ve dizinleri isme göre listelemek istiyorum yaklasık 2 saattir ugraşmaktayım lütfen yardım.
  • 08-04-2010, 16:08:37
    #2
    Üyeliği durduruldu
    yokmu bilgisi olan ?
  • 09-04-2010, 10:22:59
    #3
    Üyeliği durduruldu
    hocam hiç classla cebelleşmeden opendir, readdir ile klasörü okuyabilirsiniz. forumda benzer paylasimlar vardi
  • 09-04-2010, 12:35:02
    #4
    Üyeliği durduruldu
    sdemirkeser, saol fakat müşteri böyle istiyor ajaxda ağac şeklinde listeleme, bu script bunu yapiyor fakat listelerken kafasına göre alfabe düzeni yok, müşteri alfabe düzenine göre istiyor, localde (windowsda) harfe göre sıralıyor, fakat sunucuda kafasına göre listeleme yapiyor, sunucu ayarlarını oynama şansım yok, mecbur koddan bulmam gerekiyor.

    üsteki borwse.classs.php di
    bu browse.php
    Alıntı
    <?php
    // load error handling script, config and browse class
    require_once ('error_handler.php');
    require_once ('browse.class.php');
    require_once ('config.php');

    // Create new browse object
    $browser = new Browse();
    $browser->invalid_files = $invalid_files;
    //generate response
    $response =
    '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' .
    '<response>' .
    '<result>' .
    $browser->BrowseAJAX($_POST['inputValue'], $_POST['fieldID']) .
    '</result>' .
    '<fieldid>' .
    $_POST['fieldID'] .
    '</fieldid>' .
    '</response>';
    // generate the response
    if(ob_get_length()) ob_clean();
    header('Content-Type: text/xml');
    echo $response;

    ?>
    buda index.php de olan dosya

    Alıntı
    <div class="left">
    <body onload="browse('open','<?=$path?>');">
    <div id="busy" align="center"><h1>Eger Goremiyorsanız Tıklayınız</h1></div>
    <p align="left"><b>
    <span id="<?=$path?>" title="open" onclick="browse(this.title,this.id);"/><h2><?=$path?></h2></span>
    </b></p>
    <p align="left">
    <span id="<?=$path?>Info"></span>
    </div>
    config dosyasi

    Alıntı
    <?php
    $path = './';
    $invalid_files = array ("\\/", "php", "css", "htaccess", "sub", "srt", "idx", "smi", "jpg", "js");
    ?>
    browser.js

    Alıntı
    var xmlHttp = createXmlHttpRequestObject();
    var serverAddress = "browse.php";
    var showErrors = true;
    var cache = new Array();
    //XMLHttpRequest instance
    function createXmlHttpRequestObject() {
    var xmlHttp;
    try {
    xmlHttp = new XMLHttpRequest();
    }
    catch(e) {
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
    "MSXML2.XMLHTTP.5.0",
    "MSXML2.XMLHTTP.4.0",
    "MSXML2.XMLHTTP.3.0",
    "MSXML2.XMLHTTP",
    "Microsoft.XMLHTTP");
    // try every id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
    try {
    xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
    }
    catch (e) {}
    }
    }
    if (!xmlHttp)
    displayError("Error creating the XMLHttpRequest object.");
    else
    return xmlHttp;
    }
    // error message
    function displayError($message) {
    if (showErrors) {
    showErrors = false;
    alert("Error encountered: \n" + $message);
    setTimeout("browse();", 10000);
    }
    }
    // the function handles the validation for any form field
    function browse(inputValue, fieldID) {
    if (xmlHttp) {
    if (fieldID) {
    if (inputValue == "close") {
    document.getElementById(fieldID).title = "open";
    document.getElementById(fieldID + "Info").innerHTML = "";
    //alert("image" + fieldID);
    if (document.getElementById("image" + fieldID))
    document.getElementById("image" + fieldID).src = "../img/folder.gif";
    return;
    }
    else {
    document.getElementById(fieldID).title = "close";
    if (document.getElementById("image" + fieldID))
    document.getElementById("image" + fieldID).src = "../img/back.gif";
    }

    inputValue = encodeURIComponent(inputValue);
    fieldID = encodeURIComponent(fieldID);
    cache.push("inputValue=" + inputValue + "&fieldID=" + fieldID);
    }
    // try to connect to the server
    try {
    if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
    && cache.length > 0) {
    // get a new set of parameters from the cache
    var cacheEntry = cache.shift();
    // make a server request to validate the extracted data
    xmlHttp.open("POST", serverAddress, true);
    xmlHttp.setRequestHeader("Content-Type",
    "application/x-www-form-urlencoded");
    xmlHttp.onreadystatechange = handleRequestStateChange;
    xmlHttp.send(cacheEntry);
    }
    if (xmlHttp.readyState == 1)
    document.getElementById("busy").innerHTML = "<h1>Sunucu Yogun</h1>";
    else
    document.getElementById("busy").innerHTML = "<h1>3D Download</h1>";
    }
    catch (e) {
    displayError(e.toString());
    }
    }
    }
    // function that handles the HTTP response
    function handleRequestStateChange() {
    // when readyState is 4, we read the server response
    if (xmlHttp.readyState == 4) {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) {
    try {
    readResponse();
    }
    catch(e) {
    displayError(e.toString());
    }
    }
    else {
    displayError(xmlHttp.statusText);
    }
    }
    }
    function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
    str = str.replace( from, to );
    idx = str.indexOf( from );
    }

    return str;
    }
    // read server's response
    function readResponse() {
    // retrieve the server's response
    var response = xmlHttp.responseText;
    amp = new RegExp("&amp;", "g");

    // server error?
    if (response.indexOf("ERRNO") >= 0
    || response.indexOf("error:") >= 0
    || response.length == 0)
    throw(response.length == 0 ? "Server error." : response);
    // get response in XML format (assume the response is valid XML)
    responseXml = xmlHttp.responseXML;
    // get the document element
    xmlDoc = responseXml.documentElement;
    result = xmlDoc.getElementsByTagName("result")[0].firstChild.data;
    fieldID = xmlDoc.getElementsByTagName("fieldid")[0].firstChild.data;
    // find the HTML element that displays the error
    result = result.replace("amp", "&");

    message = document.getElementById(fieldID + "Info");
    message.innerHTML = result;
    // show the error or hide the error
    //message.className = (result == "0") ? "error" : "hidden";
    // call validate() again, in case there are values left in the cache
    setTimeout("browse();", 500);
    }
    error_handler.php

    Alıntı
    <?php
    // set the user error handler method to be error_handler
    set_error_handler('error_handler', E_ALL);
    // error handler function
    function error_handler($errNo, $errStr, $errFile, $errLine) {
    // clear any output that has already been generated
    if(ob_get_length()) ob_clean();
    // output the error message
    $error_message = 'ERRNO: ' . $errNo . chr(10) .
    'TEXT: ' . $errStr . chr(10) .
    'LOCATION: ' . $errFile .
    ', line ' . $errLine;
    echo $error_message;
    // prevent processing any more PHP scripts
    exit;
    }
    ?>
    bunun haricinde başka birşey yok,
  • 09-04-2010, 14:03:08
    #5
    Üyeliği durduruldu
    return $this->dirList($fieldID, $inputValue);
    kisminda sort etmeniz lazim hocam o zaman.

    return sort($this->dirList($fieldID, $inputValue));

    gibi calisabilir
  • 09-04-2010, 14:13:28
    #6
    Üyeliği durduruldu
    yok kardeş olmadı gene, string hatasi veriyor sanırım,

    boyle bi hata
  • 09-04-2010, 14:59:43
    #7
    Üyeliği durduruldu
    string bir veriyi sort etmeye çalışıyorsunuz

    if ($this->handle = opendir($folder)) {
    while (false !== ($this->file = readdir($this->handle))) {
    array_push($this->files,$this->file);

    }

    bu satırın altında
    sort($this->files);
    dene sene erhan
  • 09-04-2010, 15:01:33
    #8
    Üyeliği durduruldu
    şaho gözlerinden öperim oldu saolasin (:
  • 09-04-2010, 15:47:28
    #9
    Üyeliği durduruldu
    bişey değil kardeş : )