PHP¶ÔÎļþµÄ´¦Ài
PHP ÔÚþÎñÆ÷¶ËÎļþµÄÓ¦ÓÃÉÏ£¬Ïa¹ØµÄ¶³e²»½o½oÔÚÓÚÓû§Óe*þÎñÆ÷×ÊÁÏ¿a¼aµÄ¸÷ÖÖÁ¬½Ó´aeÈ¡²Ù×÷£¬Ò²¿ÉÒÔͨ¹ý PHP ÄÚ½¨µÄÎļþ´¦Àiº¯Êý£¬À´½øÐÐÒ»°aÎļþ´¦Ài²Ù×÷¡£
basename -- µ»Ø¾¶ÖеÄÎļþÃu²¿Ö
Ói¨¸ñʽ£º$path = "/home/httpd/html/index.php";
$file = basename($path); // $file is set to "index.php"
$file = basename($path,".php"); // $file is set to "index"
pathinfo()£ºÖÎoÎļþµ±Ç°Â¾¶
Ói¨¸ñʽ£º$path_parts = pathinfo("/www/htdocs/index.html");
echo $path_parts["dirname"] . "\n"; /www/htdocs Îļþ¾¶
echo $path_parts["basename"] . "\n"; index.html ÎļþÓeÀ(C)Õ¹Ãu
echo $path_parts["extension"] . "\n"; html Îļþ¸ñʽ
ÎļþÀaÐÍÓeÏa¹ØÐÅÏ¢
filesize()£º¼ÆËaÎļþµÄ´oС£¨byte£(C)
Ói¨¸ñʽ£º$bytes=filesize(¡°a.txt¡±);
echo $bytes round($bytes/1024,2);
fileatime()£ºÎļþ×iºoÒ»´ÎÃÎÊʱ¼a£¨Ê±¼a´Á£(C)
Ói¨¸ñʽ£ºecho date(¡°Y-m-d g:i:sa¡±,fileatime);
filectime()£ºÎļþ½¨Á¢Ê±¼a
Ói¨¸ñʽ£ºecho date(¡°Y-m-d g:i:sa¡±,filectime);
filemtime()£ºÎļþ×iºoÒ»´Î¸uÐÂʱ¼a
Ói¨¸ñʽ£ºecho date(¡°Y-m-d g:i:sa¡±,filemtime);
fileperms()£ºÎļþÊoÐÔÒÔ¼°È¨ÏÞ10½øÖÆ
Ói¨¸ñʽ£ºecho substr(base_convert(fileperms(a.txt),10,8),3);
fileowner()£ºÎļþËuÓÐÕßµÄuid£¨½oÔÚLinuxϵͳÏÂÓÐÓã(C)
Ói*¨¸ñʽ£ºecho fileowner(¡°a.txt¡±);
ÎļþµÄ²Ù×÷
'r' Ö»¶Á½Ê½´o¿ª£¬½«ÎļþÖ¸ÕeÖ¸ÏoÎļþÍ¡£
'r+' ¶Áд½Ê½´o¿ª£¬½«ÎļþÖ¸ÕeÖ¸ÏoÎļþÍ¡£
'w' дÈe½Ê½´o¿ª£¬½«ÎļþÖ¸ÕeÖ¸ÏoÎļþͲ¢½«Îļþ´oС½ØΪÁa¡£Èç¹uÎļþ²»´aeÔÚÔo³¢ÊÔ´´½¨Ö®¡£
'w+' ¶Áд½Ê½´o¿ª£¬½«ÎļþÖ¸ÕeÖ¸ÏoÎļþͲ¢½«Îļþ´oС½ØΪÁa¡£Èç¹uÎļþ²»´aeÔÚÔo³¢ÊÔ´´½¨Ö®¡£
'a' дÈe½Ê½´o¿ª£¬½«ÎļþÖ¸ÕeÖ¸ÏoÎļþÄ(C)β¡£Èç¹uÎļþ²»´aeÔÚÔo³¢ÊÔ´´½¨Ö®¡£
'a+' ¶Áд½Ê½´o¿ª£¬½«ÎļþÖ¸ÕeÖ¸ÏoÎļþÄ(C)β¡£Èç¹uÎļþ²»´aeÔÚÔo³¢ÊÔ´´½¨Ö®¡£
'x' ´´½¨²¢ÒÔдÈe½Ê½´o¿ª£¬½«ÎļþÖ¸ÕeÖ¸ÏoÎļþÍ¡£Èç¹uÎļþÒÑ´aeÔÚ£¬Ôo fopen() µ÷ÓÃʧ°Ü²¢µ»Ø FALSE£¬²¢Éu³ÉÒ»Ìo E_WARNING ¼¶±ðµÄ´iÎoÐÅÏ¢¡£Èç¹uÎļþ²»´aeÔÚÔo³¢ÊÔ´´½¨Ö®¡£ÕaºÍ¸ø µ×²aµÄ open(2) ϵͳµ÷ÓÃÖ¸¶¨ O_EXCL|O_CREAT ±e¼ÇÊǵȼ۵ġ£´ËÑ¡Ïi±» PHP 4.3.2 ÒÔ¼°ÒÔºoµÄ°ae±¾ËuÖ§³Ö£¬½oÄÜÓÃÓÚ±¾µØÎļþ¡£
'x+' ´´½¨²¢ÒÔ¶Áд½Ê½´o¿ª£¬½«ÎļþÖ¸ÕeÖ¸ÏoÎļþÍ¡£Èç¹uÎļþÒÑ´aeÔÚ£¬Ôo fopen() µ÷ÓÃʧ°Ü²¢µ»Ø FALSE£¬²¢Éu³ÉÒ»Ìo E_WARNING ¼¶±ðµÄ´iÎoÐÅÏ¢¡£Èç¹uÎļþ²»´aeÔÚÔo³¢ÊÔ´´½¨Ö®¡£ÕaºÍ¸ø µ×²aµÄ open(2) ϵͳµ÷ÓÃÖ¸¶¨ O_EXCL|O_CREAT ±e¼ÇÊǵȼ۵ġ£´ËÑ¡Ïi±» PHP 4.3.2 ÒÔ¼°ÒÔºoµÄ°ae±¾ËuÖ§³Ö£¬½oÄÜÓÃÓÚ±¾µØÎļþ¡£
fopen() -- ´o¿ªÎļþ»oÕß URL
fclose() -- ¹Ø±ÕÒ»¸oÒÑ´o¿ªµÄÎļþÖ¸Õe
fread() -- ¶ÁÈ¡ÎļþÄÚÈÝ
fwrite£¨£(C)--дÈeÎļþ
Ói¨¸ñʽ£ºif(!$f=@fopen("file03.php","x")){//´o¿ªÒ»¸oÎļþ x½*¨Ð´Èe
die("Îļþ¶Áȡʧ°Ü"); //¶Áȡʧ°Ü
}
fwrite($f,"kkkkkkkkkk"); //ÏoÄǸoÎļþд дʲô
echo fread($f,10); //¶ÁÈ¡Õa¸oÎļþµÄÄÚÈÝ
fclose($f); ¹Ø±Õ´o¿ªÎļþ
file() -- °ÑÕu¸oÎļþ¶ÁÈeÒ»¸oÊý×eÖÐ
Ói¨¸ñʽ£º$arr=file("file03.php");
print_r($arr); //¶ÁÈ¡Îļþµ»ØÊý×e
readfile() --¶ÁÈeÒ»¸oÎļþ²¢Ð´Èeµ½Êa³o»º³a¡£
Ói*¨¸ñʽ£º$str=readfile("file03.php");
echo $str; Êa³o
Ò»¸oÎļþ¼ÇÊýÆ÷µÄд¨£º
$f=fopen("file03.php","r");
$i=fread($f,1000);
echo "ÕaÊÇÄuµÚ{$i}´ÎÃÎÊ";
fclose($f);
$f=fopen("file03.php","w");
$i++;
fwrite($f,$i);
fclose($f);
file_get_contents() ¨C ½«Õu¸oÎļþ¶ÁÈeÒ»¸o×Ö*u´®
Ói*¨¸ñʽ£ºfile_get_contents(ÎļþÃu³Æ»oURL)
file_put_contents() ¨C?½«Ò»¸o×Ö*u´®Ð´ÈeÎļþ,ºÍÒÀ´Îµ÷Óà fopen()£¬fwrite() ÒÔ¼° fclose() ¹¦ÄÜÒ»Ñu
file_put_contents(ÎļþÃu³Æ,дÈeÊý¾Ý)
feof() \-- ²aÊÔÎļþÖ¸ÕeÊÇ*ñµ½ÁËÎļþ½aÊøµÄλÖÃ
ftell() \-- *µ»ØÎļþÖ¸Õe¶Á/дµÄλÖÃ
Ói*¨¸ñʽftell(ÎļþÖ¸Õe)
flock() \-- Ça±aµÄ×ÉѯÎļþËø¶¨
Ói*¨¸ñʽ£ºflock£¨ÎļþÖ¸Õe£¬¿ØÖƲÎÊý£(C)
ÎļþÖ¸Õe:ÊÇÒ»¸oÒѾ´o¿ª£¨fopen£(C)µÄÎļþÖ¸Õe¿ØÖƲÎÊý£º
¡°LOCK_SH¡±±iʾҪȡµÃ¹²ÏiËø¶¨£¨¶ÁÈ¡³ÌÐo),(PHP4.0.1ÒÔÇ°°ae±¾ÉeÖÃ1£(C)¡£
¡°LOCK_EX¡±±iʾҪȡµÃ¶ÀÕ¼Ëø¶¨£¨Ð´Èe³ÌÐo),(PHP4.0.1ÒÔÇ°°ae±¾ÖÐÉeÖÃΪ 2£(C)¡£
¡°LOCK_UN¡±±iʾҪÊÍ*ÅËø¶¨£¨ÎÞÂÛ¹²Ïi»o¶ÀÕ¼),(PHP4.0.1ÒÔÇ°°ae±¾ÖÐÉeÖÃΪ 3£(C)¡£
¡°LOCK_NB¡±±iʾÈç¹uÄa²»Ï£Íu flock() ÔÚËø¶¨Ê±¶ÂÈu£¬Ôo¸ø¿ØÖƲÎÊýÔÙ¼ÓÉÏÕa¸o²ÎÊý
fseek( ) \-- ÔÚÎļþÖ¸ÕeÖж¨Î»
Ói*¨½a¹¹£º fseek£¨ÎļþÖ¸Õe£¬Òƶ¯×ÖÔªÊý [£¬ÆðʼλÖó£Êý]£(C)
ÎļþÖ¸Õe£º²»ÄÜÓÃÓÚÔÚ fopen() ÖÐÒÔ ¡°http://¡± »o ¡°ftp://¡± ¸ñʽ´o¿ªËu*µ»ØµÄÎļþÖ¸Õe¡£
Òƶ¯×ÖÔªÊý£ºÎªÕýÊýʱ£¬½«ÎļþÖ¸ÕeÏoÇ°Òƶ¯Ö¸¶¨¸oÊý£ºÎª¸ºÊýʱ£¬½«ÎļþÖ¸ÕeÏoºoÒƶ¯Ö¸¶¨¸oÊý£º
ÆðʼλÖó£Êý£º
SEEK_CUR - Ée¶¨Î»ÖÃΪµ±Ç°Î»Öá£
SEEK_SET - Ée¶¨Î»ÖõÈÓÚÎļþ¿ªÍ*¡££¨Ä¬ÈÏÖµ£(C)
SEEK_END - Ée¶¨Î»ÖÃΪÎļþβ¡£
rewind( ) \-- µ¹»ØÎļþÖ¸ÕeµÄλÖã¬Ò²¾ÍÊǽ«ÎļþÖ¸ÕeÒÆÏoÎļþµÄ¿ªÍ*λÖá£
Ói*¨½a¹¹£º rewind£¨ÎļþÖ¸Õe£(C)
×¢Òa£ºÈç¹u½«ÎļþÒÔ¸½¼Ó£¨¡°a¡± »oÕß ¡°a+¡±£(C)ģʽ´o¿ª£¬Ð´ÈeÎļþµÄÈκÎÊý¾Ý×ÜÊÇ»a±»¸½¼ÓÔÚºoÃae£¬²»¹ÜÎļþÖ¸ÕeµÄλÖÃ
chgrp( ) \-- ¸Ä±aÎļþËuÊoµÄ×e
Ói*¨½a¹¹£ºchgrp£¨ÎļþÃu³Æ£¬Èº×eÃu³Æ£(C)
filegroup( ) \-- È¡µÃÎļþµÄ×e
Ói*¨½a¹¹£ºfilegroup(ÎļþÃu³Æ)
chmod( ) \-- ¸Ä±aÎļþģʽ
Ói*¨½a¹¹£ºchmod(ÎļþÃu³Æ£¬È¨ÏÞ³£Êý)755 666
chown( ) \-- ¸Ä±aÎļþµÄËuÓÐÕß
Ói*¨½a¹¹£ºchown(ÎļþÃu³Æ£¬Ê¹ÓÃÕß)
fileowner( ) \-- È¡µÃÎļþµÄËuÓÐÕß
Ói*¨½a¹¹£ºfileowner(ÎļþÃu³Æ)
posix_getpwuid() À´½«Æa½aÎoΪÓû§Ãu¡£
copy( ) \-- ¿½±´Îļþ
Ói*¨½a¹¹£ºcopy(À´Ô´Îļþ£¬Ä¿µÄÎļþ)
*µ»ØÀaÐÍ£ºboolÐÍ£¬Èç¹u³É¹¦Ôo*µ»Ø TRUE£¬Ê§°ÜÔo*µ»Ø FALSE¡£
²ÎÊý˵Ã÷£º½«À´Ô´Îļþ¿½±´µ½Ä¿µÄÎļþ¡£
unlink( ) \-- ɾ³ýÎļþ
Ói*¨½a¹¹£ºunlink(Ä¿±eÎļþ)
*µ»ØÀaÐÍ£ºboolÐÍ£¬Èç¹u³É¹¦Ôo*µ»Ø TRUE£¬Ê§°ÜÔo*µ»Ø FALSE¡£
²ÎÊý˵Ã÷£ºÉ¾³ýÖ¸¶¨µÄÄ¿±eÎļþ
rename( ) \-- ÖØÃuÃuÒ»¸oÎļþ»oĿ¼
Ói*¨½a¹¹£ºrename(¾ÉÎļþÃu£¬ÐÂÎļþÃu)
*µ»ØÀaÐÍ£ºboolÐÍ£¬Èç¹u³É¹¦Ôo*µ»Ø TRUE£¬Ê§°ÜÔo*µ»Ø FALSE¡£
²ÎÊý˵Ã÷£º³¢Ê԰ѾÉÎļþÃuÖØÃuÃuΪÐÂÎļþÃu¡£
ÎļþÊoÐÔ´¦Ài
file_exists( ) \-- ¼i²eÎļþ»oĿ¼ÊÇ*ñ´aeÔÚ
Ói*¨½a¹¹£ºfile_exists(ÎļþÃu³Æ)
*µ»ØÀaÐÍ£ºboolÐÍ,Èo´aeÔÚ*µ»Ø true,*ñÔo*µ»Ø false¡£
filesize( ) \-- È¡µÃÎļþ´oС
Ói*¨½a¹¹£ºfilesize(ÎļþÃu³Æ)
*µ»ØÀaÐÍ£º*µ»ØÎļþ´oС×Ö½ÚÊý£¬Èo³o´i*µ»Ø false.
filetype( ) \-- È¡µÃÎļþÀaÐÍ
Ói*¨½a¹¹£ºfiletype(ÎļþÃu³Æ)
*µ»ØÀaÐÍ£º*µ»ØÎļþÀaÐÍ¡£¿ÉÄܵÄÖµÓÐ fifo£¬char£¬dir£¬block£¬link£¬file ºÍ unknown¡£ ³o´iÔo*µ»Ø false
is_dir( ) \-- Åжϸø¶¨ÎļþÃuÊÇ*ñÊÇÒ»¸oĿ¼
Ói*¨½a¹¹£ºis_dir£¨Ãu³Æ£(C)
*µ»ØÀaÐÍ£ºÈç¹uÎļþÃu´aeÔÚ²¢ÇÒÊÇÒ»¸oĿ¼Ôo*µ»Ø true£¬*ñÔo*µ»Ø false¡£
is_executable( ) \-- Åжϸø¶¨ÎļþÃuÊÇ*ñ¿ÉÖ´ÐÐ
Ói*¨½a¹¹£ºis_executable£¨Ãu³Æ£(C)
*µ»ØÀaÐÍ£ºÈç¹uÎļþ´aeÔÚÇÒ¿ÉÖ´ÐÐÔo*µ»Ø TRUE£¬*ñÔo*µ»Ø FALSE¡£
is_file( ) \-- Åжϸø¶¨ÎļþÃuÊÇ*ñΪһ¸oÕý³£µÄÎļþ
Ói*¨½a¹¹£ºis_file(Ãu³Æ)
*µ»ØÀaÐÍ£ºÈç¹uÎļþ´aeÔÚÇÒΪÕý³£µÄÎļþÔo*µ»Ø TRUE¡£
is_link( ) \-- Åжϸø¶¨ÎļþÃuÊÇ*ñΪһ¸o*uºÅÁ¬½Ó
Ói*¨½a¹¹£ºis_link(Ãu³Æ)
*µ»ØÀaÐÍ£ºÈç¹uÎļþ´aeÔÚ²¢ÇÒÊÇÒ»¸o*uºÅÁ¬½ÓÔo*µ»Ø true¡£
is_readable( ) \-- Åжϸø¶¨ÎļþÃuÊÇ*ñ¿É¶Á
Ói*¨½a¹¹£ºis_readable£¨ÎļþÃu³Æ£(C)
*µ»ØÀaÐÍ£ºÈç¹uÎļþ´aeÔÚ²¢ÇҿɶÁÔo*µ»Ø TRUE¡£
is_writable( ) \-- Åжϸø¶¨µÄÎļþÃuÊÇ*ñ¿Éд
Ói*¨½a¹¹£ºis_writable(ÎļþÃu³Æ)
*µ»ØÀaÐÍ£ºÈç¹uÎļþ´aeÔÚ²¢ÇÒ¿ÉдÔo*µ»Ø TRUE¡£
ʵÏÖiterator½Ó¿ÚµÄĿ¼¶ÁÈ¡
Iterator½Ó¿ÚµÄ±e×¼*½*¨
current()£º*µ»Øµ±Ç°Áбi(list)ÖеÄÔªËØÖµ¡£
next()£ºÓÃÓÚÔÚÒ»¸oÁбiÖÐÏoÏÂÒƶ¯Ò»¸oλÖá£
valid()£º¼i²aÔÚµ±Ç°ÁбiÖÐÊÇ*ñ»¹ÓÐÏÂÒ»¸oÔªËØ£¬Èç¹uÓУ¬*µ»Øtrue£¬*ñÔo*µ»Øfalse¡£
rewind()£º¿ÉÒÔ*ÃÎÊÖ¸¶¨ÌØÕ÷µÄÔªËØÁбi£¬ÔÚ¿ªÊ¼²Ù×÷iteratorʱ£¬»a½«Ö¸ÕeÉeÖÃÔÚ¶¥²¿¡£
µ±Ç°1/2Ò³ **1**2ÏÂÒ»Ò³ÔĶÁÈ«ÎÄ