note 40976 added to function.ftp-rawlist

From: Date: Thu, 25 Mar 2004 03:41:57 +0000
Subject: note 40976 added to function.ftp-rawlist
Groups: php.notes 
Request: Send a blank email to php-notes+get-67138@lists.php.net to get a copy of this message
This script will properly handle FTP servers where the returned date/time differs from the generic mm-dd-YYYY hh:mm:ss format: <?php $list = ftp_rawlist ($ftp_stream, $ftp_directory); $folders = array(); $files = array(); $links = array(); for ($i=0; $i<count($list); $i++) { //----convert tabs to blanks $list[$i] = str_replace ("\t", " ", $list[$i]); //----delete multiple blanks while (($k = strpos($list[$i], " ")) !== FALSE) $list[$i] = substr($list[$i],0,$k+1).trim(substr($list[$i],$k)); //----split link reference from filename where available if (($k = strpos($list[$i], " -> ")) !== FALSE) { $filelink = substr($list[$i], $k+4); $list[$i] = substr($list[$i], 0, $k); } else $filelink = ""; //----parse filename $k = strrpos($list[$i], " "); $filename = substr($list[$i], $k+1); $list[$i] = substr($list[$i], 0, $k); //----parse the rest of info 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, $time) = parsenext ($list[$i]); //----ok, put all this into the related array if ($filename != "." && $filename != "..") { $m = array(); $m["name"] = $filename; $m["link"] = $filelink; $m["size"] = $size; $m["time"] = $time; $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; } } sort ($folders); sort ($files); sort ($links); ?> This script works fine on any raw list that complies with the following format: permissions number owner group size time name [" -> " link_to] where time may have whatever format the FTP server wants. ;-) It also returns folders, files and links in separated sorted lists (got this idea from the note of "postmaster at alishomepage dot com" in this help page). ---- Manual Page -- http://www.php.net/manual/en/function.ftp-rawlist.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40976 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40976&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40976&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67138) next »