note 86780 added to function.ftp-rawlist

From: Date: Mon, 03 Nov 2008 16:56:17 +0000
Subject: note 86780 added to function.ftp-rawlist
Groups: php.notes 
Request: Send a blank email to php-notes+get-146090@lists.php.net to get a copy of this message
On my PC (XP and Apache installed) - ftp_rawlist (with Parameter true) does only print a folder list - no subfolders, no files. So i created this recursive function that writes all filenames (incl. paths) to a array. I tested it on Mac, Linux and Windows - it works (as long as you don't use folders with spaces...). If you need more information: feel free to set more split[x]-Options and write them to the $files-array. <? # the directory where ftp_rawlist starts $startdir = "example"; # optional Datatypefilter (leave blank if not needed) $suffix = "gif,png,jpeg,pdf,php"; # ftp-login $ftp_server = ""; $ftp_user = ""; $ftp_pw = ""; $ftp_mode = ""; $conn_id = ftp_connect($ftp_server); ftp_login($conn_id, $ftp_user, $ftp_pw) OR die("<br>ftp-login failed"); ftp_pasv($conn_id, true); #********************************************************************* # create filelist (recursiv) #********************************************************************* $files = array(); # must be defined here $files = raw_list("$startdir"); #********************************************************************* # print result #********************************************************************* $i = 0; $count = count($files); while ($i < $count): echo "$files[$i]<br>"; $i++; endwhile; ftp_close($conn_id); #********************************************************************* # rawlist in recursive form (without parameter true!!!) #********************************************************************* function raw_list($folder) { Global $conn_id; Global $suffix; Global $files; $suffixes = explode(",", $suffix); $list = ftp_rawlist($conn_id, $folder); $anzlist = count($list); $i = 0; while ($i < $anzlist): $split = preg_split("/[\s]+/", $list[$i], 9, PREG_SPLIT_NO_EMPTY); $ItemName = $split[8]; $endung = strtolower(substr(strrchr($ItemName,"."),1)); $path = "$folder/$ItemName"; if (substr($list[$i],0,1) === "d" AND substr($ItemName,0,1) != "."): # array_push($files, $path); # write directory in array if desired raw_list($path); elseif (substr($ItemName,0,2) != "._" AND in_array($endung,$suffixes)): array_push($files, $path); endif; $i++; endwhile; return $files; } ?> Ueli, Zurich ---- Server IP: 217.160.72.57 Probable Submitter: 81.221.179.86 ---- Manual Page -- http://www.php.net/manual/en/function.ftp-rawlist.php Edit -- https://master.php.net/note/edit/86780 Del: integrated -- https://master.php.net/note/delete/86780/integrated Del: useless -- https://master.php.net/note/delete/86780/useless Del: bad code -- https://master.php.net/note/delete/86780/bad+code Del: spam -- https://master.php.net/note/delete/86780/spam Del: non-english -- https://master.php.net/note/delete/86780/non-english Del: in docs -- https://master.php.net/note/delete/86780/in+docs Del: other reasons-- https://master.php.net/note/delete/86780 Reject -- https://master.php.net/note/reject/86780 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146090) next »