note 44079 deleted from function.ftp-rawlist by crell

From: Date: Thu, 31 Mar 2022 19:30:20 +0000
Subject: note 44079 deleted from function.ftp-rawlist by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217906@lists.php.net to get a copy of this message
Note Submitter: soon7 at wanadoo dot fr ---- Hi all ! ther is a litlle mistake in the naivesong 's message . Indeed , you stop to parse too early ... I tried and fix it like this : <? // getting the list $list = ftp_rawlist ($ftp_stream, $ftp_directory); $folders = array(); $files = array(); $links = array(); for ($i=0; $i<count($list); $i++) { //----convert tabs to blanks //----delete multiple blanks // Here begin my modifications list ($permissions, $list[$i]) = parsenext ($list[$i]); list ($number, $list[$i]) = parsenext ($list[$i]); list ($owner, $list[$i]) = parsenext ($list[$i]); list ($group, $list[$i]) = parsenext ($list[$i]); list ($size, $list[$i]) = parsenext ($list[$i]); list ($timeMonth,$list[$i]) = parsenext ($list[$i]); list ($timeDay,$list[$i]) = parsenext ($list[$i]); list ($timeTime,$list[$i]) = parsenext ($list[$i]); $filename=$list[$i]; // by taking $filename in last position , it works even if there is some space in its name //then we put it in the m array with the new things //----ok, put all this into the related array if ($filename != "." && $filename != "..") { $m = array(); $m["name"] = $filename; $m["link"] = $filelink; $m["size"] = afficherPoidsFichier($size); $m["month"] = $timeMonth; $m["day"] = $timeDay; $m["time"] = $timeTime; $m["owner"] = $owner; $m["group"] = $group; $m["permissions"] = $permissions; if (substr($permissions, 0, 1) == "d") $folders[count($folders)] = $m; else if (substr($permissions, 0, 1) == "l") $links[count($files)] = $m; else $files[count($files)] = $m; } } // you can sort $folders , $files , $links after if u want // afficherPoidsFichier($size) is a little function i found in this site at filesize() , works good ! // Just give the good size function afficherPoidsFichier($size) { $sizes = Array('o', 'Ko', 'Mo', 'Go'); $ext = $sizes[0]; for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) { $size = $size / 1024; $ext = $sizes[$i]; } return round($size, 2).' '.$ext; } ?>

« previous php.notes (#217906) next »