<?PHP/** * File Operation*///Common Operations$file=NewSplfileinfo (' D:/workspace/xlyy/spl/test.txt ');$file _info=Array( ' Getatime ' =$file->getatime (),//Last access Time' Getbasename ' =$file->getbasename (),//Get file name' Getctime ' =$file->getctime (),//Get inode modification Time' GetExtension ' =$file->getextension (),//file name extension' GetFileName ' =$file->getfilename (),//file name' Getgroup ' =$file->getgroup (),//the group where the file resides' Getinode ' =$file->getinode (),//Get file Inode' Getlinktarget ' =$file->getlinktarget (),//get File link destination file' Getmtime ' =$file->getmtime (),//file Last modified time' GetOwner ' =$file->getowner (),//Get file owner' GetPath ' =$file->getpath (),//get a path without a file name' GetPathInfo ' =$file->getpathinfo (),//ancestor path Splfileinfo object' GetPathName ' =$file->getpathname (),//Full path' Getperms ' =$file->getperms (),//Permissions' Getrealpath ' =$file->getrealpath (),//Absolute Path' GetSize ' =$file->getsize (),//file Size (bytes)' GetType ' =$file-GetType(),//file Type File/dir/link' Isdir ' =$file->isdir (),//whether it is a directory' Isfile ' =$file->isfile (),//whether it is a file' Islink ' =$file->islink (),//whether it is a file' IsExecutable ' =$file->isexecutable (),//whether it can be executed' IsReadable ' =$file->isreadable (),//whether it is readable' IsWritable ' =$file->iswritable (),//whether it can be written);Echo' <pre> ';Print_r($file _info);Echo' </pre> ';Echo' ;//Traversal OperationsTry{ foreach(NewSplfileobject (' Test.txt ') as $line){//iterate through the contents of a file Echo $line; }}Catch(Exception $e){ Echo $e-getMessage ();}Echo' ;//finds the specified rowTry{ $file=NewSplfileobject (' Test.txt '); $file->seek (2); Echo $file- Current();}Catch(Exception $e){ Echo $e-getMessage ();}//writing to a CSV file$list=Array( Array(' aaaa ', ' bbbbb ', ' cccccc ', ' ddddddddd '),Array(' 123 ', 456,789),Array(' AA ', ' BB '),);$file=NewSplfileobject (' File.csv ', ' W ');foreach($list as $fields){ $file->fputcsv ($fields);}
SPL Processing files (file details, file traversal, querying a specified line, writing to a CSV file)