[php] list_files() function

Status
Not open for further replies.

natsu90

Active Member
144
2009
0
0
i'm noob and sorry if this is a noob question. i wanna recode this so they'll only result one link and the latest one.

can't any hero wanna help me bout this? i'll very appreciate and sorry for my english. this code from leechviet.

PHP:
    function datecmp($a, $b)
    {
        return ($a[1] < $b[1]) ? 1 : 0;
    }
    function list_files()
    {
        $files = array();
        foreach ($this->jobs as $job)
        {
            if ($job['owner']!=$this->owner && !$this->bypass)
            {
                continue;
            }
            $files[] = array($job['hash'], $job['mtime'], $job['filename'], $job['msize'], $job['speed']/1024, empty($job['size']) ? 'N/A' : sprintf('%.1f%%', $job['msize']/$job['size']*100), $job['size'], $job['type']);
        }
        usort($files, array($this, 'datecmp')); //sorting the newest to oldest links
        $scheme = "<center><b><a href='?d=%s'>%s</a></b></center>";
                $this->CheckMBIP();
        $data = "";
                $data .= "<center><b>Your downloads: </b></center>";            
        foreach ($files as $file)
        {
            if ($file[7] == 'remote')
            {
                $data .= sprintf($scheme, $file[0], $file[2]);
            }
        }
        $data .= "";
        echo $data;
    }
 
2 comments
PHP:
function datecmp($a, $b)
    {
        return ($a[1] < $b[1]) ? 1 : 0;
    }
    function list_files()
    {
        $files = array();
        foreach ($this->jobs as $job)
        {
            if ($job['owner']!=$this->owner && !$this->bypass)
            {
                continue;
            }
            $files[] = array($job['hash'], $job['mtime'], $job['filename'], $job['msize'], $job['speed']/1024, empty($job['size']) ? 'N/A' : sprintf('%.1f%%', $job['msize']/$job['size']*100), $job['size'], $job['type']);
        }
        usort($files, array($this, 'datecmp')); //sorting the newest to oldest links
        $scheme = "<center><b><a href='?d=%s'>%s</a></b></center>";
                $this->CheckMBIP();
        $data = "";
                $data .= "<center><b>Your downloads: </b></center>";            
        $count = count($files);
        $count--;
        
        foreach ($files[$count] as $file)
        {
            if ($file[7] == 'remote')
            {
                $data .= sprintf($scheme, $file[0], $file[2]);
            }
        }
        $data .= "";
        echo $data;
    }
 
@nuclea
that didnt work either but thanks for your reply. really appreaciate that. somehow i've got it work. using current() function.

PHP:
    function datecmp($a, $b)
    {
        return ($a[1] < $b[1]) ? 1 : 0;
    }
    function list_files()
    {
        $files = array();
        foreach ($this->jobs as $job)
        {
            if ($job['owner']!=$this->owner && !$this->bypass)
            {
                continue;
            }
            $files[] = array($job['hash'], $job['mtime'], $job['filename'], $job['msize'], $job['speed']/1024, empty($job['size']) ? 'N/A' : sprintf('%.1f%%', $job['msize']/$job['size']*100), $job['size'], $job['type']);
        }
        usort($files, array($this, 'datecmp')); //sorting the newest to oldest links
        $scheme = "<center><b><a href='?d=%s'>%s</a></b></center>";
                $this->CheckMBIP();
        $data = "";
                $data .= "<center><b>Your downloads: </b></center>";            
        $files=array(current($files)); //return current value
        foreach ($files as $file)
        {
            if ($file[7] == 'remote')
            {
                $data .= sprintf($scheme, $file[0], $file[2]);
            }
        }
        $data .= "";
        echo $data;
    }
thanks again. solved.
 
Status
Not open for further replies.
Back
Top