phpÎļþ¼Ð²Ù×÷º¯Êý
string basename ( string path [, string suffix] )
¸ø³oÒ»¸o°uº¬ÓÐÖ¸ÏoÒ»¸oÎļþµÄȫ¾¶µÄ×Öu´®£¬±¾º¯Êýµ»Ø»u±¾µÄÎļþÃu¡£Èç¹uÎļþÃuÊÇÒÔ suffix ½aÊøµÄ£¬ÄÇÕaÒ»²¿ÖÒ²»a±»È¥µo¡£
ÔÚ Windows ÖУ¬Ð±Ïߣ¨/£(C)ºÍ´Ð±Ïߣ¨£(C)¶¼¿ÉÒÔÓÃ×÷Ŀ¼ָou¡£ÔÚÆaËu»¾³ÏÂÊÇбÏߣ¨/£(C)¡£
string dirname ( string path )
¸ø³oÒ»¸o°uº¬ÓÐÖ¸ÏoÒ»¸oÎļþµÄȫ¾¶µÄ×Öu´®£¬±¾º¯Êýµ»ØÈ¥µoÎļþÃuºoµÄĿ¼Ãu¡£
ÔÚ Windows ÖУ¬Ð±Ïߣ¨/£(C)ºÍ´Ð±Ïߣ¨£(C)¶¼¿ÉÒÔÓÃ×÷Ŀ¼ָou¡£ÔÚÆaËu»*¾³ÏÂÊÇбÏߣ¨/£(C)¡£
array pathinfo ( string path [, int options] )
pathinfo() µ»ØÒ»¸oÁªºÏÊý×e°uº¬ÓÐ path µÄÐÅÏ¢¡£°uÀ¨ÒÔϵÄÊý×eµ¥Ôª£ºdirname£¬basename ºÍ extension¡£
¿ÉÒÔͨ¹ý²ÎÊý options Ö¸¶¨Òªµ»ØÄÄÐ(C)µ¥Ôª¡£ËuÃÇ°uÀ¨£ºPATHINFO_DIRNAME£¬PATHINFO_BASENAME ºÍ PATHINFO_EXTENSION¡£Ä¬ÈÏÊÇ*µ»ØÈ«²¿µÄµ¥Ôª¡£
string realpath ( string path )
realpath() À(C)Õ¹ËuÓеÄuºÅÁ¬½Ó²¢ÇÒ´¦ÀiÊaÈeµÄ path ÖÐµÄ ¡®/./', ¡®/../' ÒÔ¼°¶aÓaµÄ ¡®/' ²¢µ»Ø¹ae¶»¯ºoµÄ¾ø¶Ô¾¶Ãu¡£µ»ØµÄ¾¶ÖÐûÓÐuºÅÁ¬½Ó£¬'/./' »o ¡®/../' ³ÉÖ¡£
realpath() ʧ°Üʱµ»Ø FALSE£¬±ÈÈç˵Îļþ²»´aeÔڵĻ°¡£ÔÚ BSD ϵͳÉÏ£¬Èç¹u½o½oÊÇ path ²»´aeÔڵĻ°£¬PHP ²¢²»»aÏñÆaËuϵͳÄÇÑuµ»Ø FALSE¡£
bool is_dir ( string filename )
Èç¹uÎļþÃu´aeÔÚ²¢ÇÒΪĿ¼Ôoµ»Ø TRUE¡£Èç¹u filename ÊÇÒ»¸oÏa¶Ô¾¶£¬Ôo°´ÕÕµ±Ç°¹¤×÷Ŀ¼¼i²eÆaÏa¶ÔÂ*¾¶¡£
×¢: ±¾º¯ÊýµÄ½a¹u»a±»»º´ae¡£¸u¶aÐÅÏ¢²Î¼u clearstatcache()¡£
resource opendir ( string path [, resource context] )
´o¿ªÒ»¸oĿ¼¾a±u£¬¿ÉÓÃÓÚÖ®ºoµÄ closedir()£¬readdir() ºÍ rewinddir() µ÷ÓÃÖС£
string readdir ( resource dir_handle )
µ»ØĿ¼ÖÐÏÂÒ»¸oÎļþµÄÎļþÃu¡£ÎļþÃuÒÔÔÚÎļþϵͳÖеÄÅÅÐoµ»Ø¡£
void closedir ( resource dir_handle )
¹Ø±ÕÓÉ dir_handle Ö¸¶¨µÄĿ¼Á÷¡£Á÷±ØÐe֮ǰ±» opendir() Ëu´o¿ª¡£
void rewinddir ( resource dir_handle )
½« dir_handle Ö¸¶¨µÄĿ¼Á÷ÖØÖõ½Ä¿Â¼µÄ¿ªÍ*¡£
array glob ( string pattern [, int flags] )
glob() º¯ÊýÒÀÕÕ libc glob() º¯ÊýʹÓõĹaeÔoÑ°ÕÒËuÓÐÓe pattern Æ¥ÅaµÄÎļþ¾¶£¬ÀaËÆÓÚÒ»°a shells ËuÓõĹaeÔoÒ»Ñu¡£²»½øÐÐËoдÀ(C)Õ¹»o²ÎÊýÌae´u¡£
µ»ØÒ»¸o°uº¬ÓÐÆ¥ÅaÎļþ/Ŀ¼µÄÊý×e¡£Èç¹u³o´i*µ»Ø FALSE¡£
ÓÐЧ±e¼ÇΪ£º
GLOB_MARK - ÔÚÿ¸oµ»ØµÄÏiÄ¿ÖмÓÒ»¸oбÏß
GLOB_NOSORT - °´ÕÕÎļþÔÚĿ¼ÖгoÏÖµÄÔʼ˳Ðoµ»Ø£¨²»ÅÅÐo£(C)
GLOB_NOCHECK - Èç¹uûÓÐÎļþÆ¥ÅaÔoµ»ØÓÃÓÚËÑË÷µÄģʽ
GLOB_NOESCAPE - ´Ð±Ïß²»×ªÒaÔª×Öu
GLOB_BRACE - À(C)³a {a,b,c} À´Æ¥Åa ¡®a'£¬'b' »o ¡®c'
GLOB_ONLYDIR - ½oµ»ØÓeģʽƥÅaµÄĿ¼Ïi
×¢: ÔÚ PHP 4.3.3 °ae±¾Ö®Ç° GLOB_ONLYDIR ÔÚ Windows »oÕßÆaËu²»Ê¹Óà GNU C ¿aµÄϵͳÉϲ»¿ÉÓá£
GLOB_ERR - Í£Ö¹²¢¶ÁÈ¡´iÎoÐÅÏ¢£¨±ÈÈç˵²»¿É¶ÁµÄĿ¼£(C)£¬Ä¬ÈϵÄÇe¿oϺoÂÔËuÓдiÎo
×¢: GLOB_ERR ÊÇ PHP 5.1 Ìi¼ÓµÄ¡£
phpÎļþĿ¼²Ù×÷
н¨Îļþ
1¡¢ÏÈȶ¨ÒªÐ´ÈeÎļþµÄÄÚÈÝ
$content = 'ÄaºÃ';
2¡¢´o¿ªÕa¸oÎļþ£¨ÏµÍ³»a×Ô¶¯½¨Á¢Õa¸o¿ÕÎļþ£(C)
//¼ÙÉeн¨µÄÎļþ½Ðfile.txt£¬¶øÇÒÔÚÉϼ¶Ä¿Â¼Ï¡£w±iʾ¡®Ð´Îļþ'£¬$fpÏÂÃaeÒªÓõ½£¬±iʾָÏoij¸o´o¿ªµÄÎļþ¡£
$fp = fopen('../file.txt', 'w');
3¡¢½«ÄÚÈÝ×Öu´®Ð´ÈeÎļþ
//$fp¸aeËßϵͳҪдÈeµÄÎļþ£¬Ð´ÈeµÄÄÚÈÝÊÇ$content
fwrite($fp, $content);
4¡¢¹Ø±ÕÎļþ
fclose($fp);
˵Ã÷£ºPHP5ÖÐÌa¹(C)Á˸u*½±aµÄº¯Êýfile_put_contents£¬ÉÏÃaeµÄ4²½¿ÉÒÔÕaÑuÍe³É£º
$content = 'ÄaºÃ';
file_put_contents('file.txt',$content);
ɾ³ýÎļþ
//ɾ³ýµ±Ç°Ä¿Â¼ÏµÄarchĿ¼ÏµÄÎļþabc.txt
unlink('arch/abc.txt');
˵Ã÷£ºÏµÍ³»aµ»Ø²Ù×÷½a¹u£¬³É¹¦Ôoµ»Ø TRUE£¬Ê§°ÜÔoµ»Ø FALSE£¬¿ÉÒÔÓñaÁ¿½ÓÊÕ£¬¾ÍÖªµÀÊÇñɾ³ý³É¹¦£º
$deleteResult = unlink('arch/abc.txt');
»ñÈ¡ÎļþÄÚÈÝ
//¼ÙÉe»ñÈ¡µÄÄ¿±eÎļþÃuÊÇfile.txt£¬¶øÇÒÔÚÉϼ¶Ä¿Â¼Ï¡£»ñÈ¡µÄÄÚÈÝ*ÅÈe$content¡£
$content = file_get_contents('../file.txt');
ÐÞ¸ÄÎļþÄÚÈÝ
²Ù×÷½¨Óeн¨ÄÚÈÝ»u±¾Ò»Ñu
ÖØÃuÃuÎļþ»oĿ¼
//½«µ±Ç°Ä¿Â¼ÏµÄ×ÓĿ¼aÏÂÃaeµÄÎļþ1.gifÖØÃuÃuΪ2.gif¡£
rename('/a/1.gif', '/a/2.gif');
˵Ã÷£º¶ÔĿ¼ҲһÑu¡£ÏµÍ³»aµ»Ø²Ù×÷½a¹u£¬³É¹¦Ôoµ»Ø TRUE£¬Ê§°ÜÔoµ»Ø FALSE£¬¿ÉÒÔÓñaÁ¿½ÓÊÕ£¬¾ÍÖªµÀÊÇñÖØÃuÃu³É¹¦¡£
$renameResult = rename('/a/1.gif', '/a/2.gif');
Èç¹uÒªÒƶ¯Îļþ»oĿ¼£¬Ö»Òª½«ÖØÃuÃuºoµÄ¾¶ÉeÖÃΪеľ¶¾Í¿ÉÒÔÁË£º
//½«µ±Ç°Ä¿Â¼ÏµÄ×ÓĿ¼aÏÂÃaeµÄÎļþ1.gif£¬Òƶ¯µ½µ±Ç°Ä¿Â¼ÏµÄ×ÓĿ¼b,²¢ÇÒÖØÃuÃuΪ2.gif¡£
rename('/a/1.gif', '/b/2.gif');
²»¹ýҪעÒa£¬Èç¹uĿ¼b²»´aeÔÚ£¬¾Í»aÒƶ¯Ê§°Ü¡£
¸´ÖÆÎļþ
//½«µ±Ç°Ä¿Â¼ÏµÄ×ÓĿ¼aÏÂÃaeµÄÎļþ1.gif£¬¸´ÖƵ½µ±Ç°Ä¿Â¼ÏµÄ×ÓĿ¼b£¬²¢ÃuÃuΪ2.gif¡£
copy('/a/1.gif', '/b/1.gif');
˵Ã÷£º²»ÄܶÔĿ¼½øÐдËÏi²Ù×÷¡£
Èç¹uÄ¿±eÎļþ£¨ÉÏÃaeµÄ/b/1.gif£(C)ÒѾ´aeÔÚ£¬ÔÀ´µÄÎļþ½«±»¸²¸Ç¡£
ϵͳ»aµ»Ø²Ù×÷½a¹u£¬³É¹¦Ôoµ»Ø TRUE£¬Ê§°ÜÔoµ»Ø FALSE£¬¿ÉÒÔÓñaÁ¿½ÓÊÕ£¬¾ÍÖªµÀÊÇñ¸´ÖƳɹ¦¡£
$copyResult = copy('/a/1.gif', '/b/1.gif');
Òƶ¯Îļþ»oĿ¼
²Ù×÷½¨ºÍÖØÃuÃuÒ»Ñu
Îļþ»oĿ¼ÊÇñ´aeÔÚ
//¼i²eÉϼ¶Ä¿Â¼ÏµÄÎļþlogo.jpgÊÇñ´aeÔÚ¡£
$existResult = file_exists('../logo.jpg');
˵Ã÷£ºÈç¹uÎļþ´aeÔÚϵͳµ»Øtrue£¬ñÔo*µ»Øfalse¡£¿ÉÒÔ¶ÔĿ¼½øÐÐͬÑuµÄ²Ù×÷¡£
»ñÈ¡Îļþ´oС
//»ñÈ¡Éϼ¶Ä¿Â¼ÏµÄÎļþlogo.pngµÄ´oС¡£
$size = filesize('../logo.png');
˵Ã÷£ºÏµÍ³»a*µ»ØÒ»¸oÊý×Ö£¬±iʾÎļþµÄ´oСÊǶaÉÙ×Ö½Ú£¨bytes£(C)¡£
н¨Ä¿Â¼
//ÔÚµ±Ç°Ä¿Â¼ÏµÄĿ¼aÏÂÃaeн¨Ä¿Â¼b¡£
mkdir('/a/b');
˵Ã÷£ºÏµÍ³»aµ»Ø²Ù×÷½a¹u£¬³É¹¦Ôoµ»Ø TRUE£¬Ê§°ÜÔoµ»Ø FALSE£¬¿ÉÒÔÓñaÁ¿½ÓÊÕ£¬¾ÍÖªµÀÊÇñн¨³É¹¦£º
$mkResult = mkdir('/a/b');
ɾ³ýĿ¼
//ɾ³ýµ±Ç°Ä¿Â¼ÏµÄĿ¼aÏÂÃaeµÄ×ÓĿ¼b¡£
rmdir('/a/b');
˵Ã÷£ºÖ»ÄÜɾ³ýÇ¿ÕµÄĿ¼£¬ñÔo±ØÐeÏÈɾ³ýĿ¼ÏµÄ×ÓĿ¼ºÍÎļþ£¬ÔÙɾ³ý×ÜĿ¼
ϵͳ»aµ»Ø²Ù×÷½a¹u£¬³É¹¦Ôoµ»Ø TRUE£¬Ê§°ÜÔoµ»Ø FALSE£¬¿ÉÒÔÓñaÁ¿½ÓÊÕ£¬¾ÍÖªµÀÊÇñɾ³ý³É¹¦£º
$deleteResult = rmdir('/a/b');
»ñȡĿ¼ÖеÄËuÓÐÎļþÃu
1¡¢ÏÈ´o¿ªÒª²Ù×÷µÄĿ¼£¬²¢ÓÃÒ»¸o±aÁ¿Ö¸ÏoËu
//´o¿ªµ±Ç°Ä¿Â¼ÏµÄĿ¼picϵÄ×ÓĿ¼common¡£
$handler = opendir('pic/common');
2¡¢Ñ»µÄ¶ÁȡĿ¼ÏµÄËuÓÐÎļþ
/ÆaÖÐ$filename = readdir($handler)ÊÇÿ´ÎÑ»µÄʱºo½«¶ÁÈ¡µÄÎļþÃu¸³Öµ¸ø$filename£¬ÎªÁ˲»ÏÝÓÚËÀÑ»£¬ËuÒÔ»¹ÒªÈÃ$filename !== false¡£Ò»¶¨ÒªÓÃ!==£¬ÒoΪÈç¹uij¸oÎļþÃuÈç¹u½Ð'0'£¬»oÕßijÐ(C)±»ÏµÍ³ÈÏΪÊÇ´u±ifalse£¬ÓÃ!=¾Í»aֹͣѻ**/
while( ($filename = readdir($handler)) !== false ) {
3¡¢Ä¿Â¼Ï¶¼»aÓÐÁ½¸oÎļþ£¬Ãu×ÖΪ'.'ºÍ¡®..'£¬²»Òª¶ÔËuÃǽøÐвÙ×÷
if($filename != "." && $filename != "..") {
4¡¢½øÐд¦Ài
//ÕaÀi¼oµ¥µÄÓÃechoÀ´Êa³oÎļþÃu
echo $filename;
}
}
5¡¢¹Ø±ÕĿ¼
closedir($handler);
¶ÔÏoÊÇñÊÇĿ¼
//¼i²eÉϼ¶Ä¿Â¼ÏµÄÄ¿±e¶ÔÏologo.jpgÊÇñÊÇĿ¼¡£
$checkResult = is_dir('../logo.jpg');
˵Ã÷£ºÈç¹uÄ¿±e¶ÔÏoÊÇĿ¼ϵͳµ»Øtrue£¬ñÔo*µ»Øfalse¡£ÉÏÃaeÀý×ÓµÄ$checkResultµ±È»ÊÇfalse¡£
¶ÔÏoÊÇñÊÇÎļþ
//¼i²eÉϼ¶Ä¿Â¼ÏµÄÄ¿±e¶ÔÏologo.jpgÊÇñÊÇÎļþ¡£
$checkResult = is_file('../logo.jpg');
˵Ã÷£ºÈç¹uÄ¿±e¶ÔÏoÊÇÎļþ£¬ÏµÍ³µ»Øtrue£¬ñÔo*µ»Øfalse¡£ÉÏÃaeÀý×ÓµÄ$checkResultµ±È»ÊÇtrue¡£