note 124880 added to function.ftp-rawlist

From: Date: Sat, 04 Apr 2020 05:30:36 +0000
Subject: note 124880 added to function.ftp-rawlist
Groups: php.notes 
Request: Send a blank email to php-notes+get-214414@lists.php.net to get a copy of this message
This function will give you directly the ftp file information whether if it a file or directory or a link. /** * Retrieve file information from rawlist result function. * * @param $ftpStream * @param $fileName * * @return array */ public static function extractRawList($ftpStream, $fileName) { $info = []; # Check if the file is directory. $isDir = ftp_size($ftpStream, $fileName) === -1 ? true : false; # Throwing exception if rawlist fail to getting the file data. # If the file is a directory we back to the previous folder and lopping over it to get the dir info. if (empty($list = ftp_rawlist($ftpStream, $isDir ? $fileName . '/..' : $fileName))) throw new \RuntimeException("Unreachable server content."); # Extract date from rawlist result array. foreach ($list as $item) { # Clean the spaces. $clean = preg_replace('/\s+/', ' ', $item); # rawlist string to an array. $split_string = explode(" ", $clean); # file name. $name = $split_string[count($split_string) - 1]; # Compare the file name from rawlist with the file name that we want information from. if ($name === ($isDir ? pathinfo($fileName, PATHINFO_BASENAME) : $fileName)) { $info['chmod'] = $split_string[0]; $info['num'] = $split_string[1]; $info['owner'] = $split_string[2]; $info['group'] = $split_string[3]; $info['size'] = $split_string[4]; $info['Mtime'] = sprintf("%s %s %s", $split_string[5], $split_string[6], $split_string[7]); $info['name'] = $split_string[8]; } } return $info; } ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 105.158.187.177) ---- Manual Page -- http://php.net/manual/en/function.ftp-rawlist.php Edit -- https://master.php.net/note/edit/124880 Del: integrated -- https://master.php.net/note/delete/124880/integrated Del: useless -- https://master.php.net/note/delete/124880/useless Del: bad code -- https://master.php.net/note/delete/124880/bad+code Del: spam -- https://master.php.net/note/delete/124880/spam Del: non-english -- https://master.php.net/note/delete/124880/non-english Del: in docs -- https://master.php.net/note/delete/124880/in+docs Del: other reasons-- https://master.php.net/note/delete/124880 Reject -- https://master.php.net/note/reject/124880 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214414) next »