ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

6-3 Àɮ׳B²z¨ç¼Æ

6-3 Àɮ׳B²z¨ç¼Æ

6-3   Àɮ׳B²z¨ç¼Æ
fopen()¨ç¼Æ¤¹³\PHPµ{¦¡¦s¨úºô­¶¦øªA¾¹¤WªºÀɮסA¹ê°È¤WÀ³¥Î¤j³¡¥÷¥H¤å¦rÀɬ°¥D¡C

fopen() ¨ç¼Æ®æ¦¡
  1. resource fopen ( string filename, string mode [, int use_include_path [, resource zcontext]])
½Æ»s¥N½X
fopen()¨ç¼Æ¥u­t³d¶}±ÒÀɮסA­Y·QŪ¨úÀɮפº®e¡A«h¥²¶·°t¦Xfread()¨ç¼Æ¤@°_¨Ï¥Î¡A­Yfopen()¨ç¼Æ¥¿½T°õ¦æ«h¦^¶Ç­È¬°1¡A¤Ï¤§¦^¶Ç­È¬°0¡C»yªk¦p¤U©Ò¥Ü¡G
  1. $f=fopen(¡§Àɮ׸ô®|»P¦WºÙ¡¨,¡¨¶}±Òªº¼Ò¦¡¡¨);
½Æ»s¥N½X
¡u¶}±Òªº¼Ò¦¡¡v¦³¤U¦C¼ÆºØ¡G

³]©w­È

»¡©ú

a

Àɮ׶}±Ò¦¨ªþ¥[¼g¤J¼Ò¦¡Àɮפº¤º®e«O¯d¡A¸ê®Æ·|±qÀɮ׳̫᭱¼g¤J¡A­YÀɮפ£¦s¦b«h¦Û°Ê«Ø¥ß

a+

Àɮ׶}±Ò¦¨ªþ¥[Ū¨ú¼Ò¦¡Àɮפº¤º®e«O¯d¡A¸ê®Æ·|±qÀɮ׳̫᭱¼g¤J¡A­YÀɮפ£¦s¦b«h¦Û°Ê«Ø¥ß

r

Àɮ׶}±Ò¦¨°ßŪ¼Ò¦¡

r+

Àɮ׶}±Ò¦¨¥iŪ¥i¼g¼Ò¦¡¡A¸ê®Æ·|±qÀɮ׳̫e­±¼g¤J

w

¶}±Ò¦¨°ß¼gªºÀɮסA­ìÀɮפº®e·|³Q²M°£¡A­YÀɮפ£¦s¦b«h¦Û°Ê«Ø¥ß

w+

Àɮ׶}±Ò¦¨¥iŪ¥i¼g¼Ò¦¡¡A­ìÀɮפº®e·|³Q²M°£¡A­YÀɮפ£¦s¦b«h¦Û°Ê«Ø¥ß



¨Ò¦p:
  1. <?
  2. $myfile=fopen("test.txt","r"); //µù1
  3. $myfile=fopen("count.txt","a"); //µù2
  4. $myfile=fopen("c:\\myfile\\test.txt","r");//µù1
  5. $myfile=fopen("mem.txt","w");//µù2
  6. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

µù1¡G
·í¥H¡ur¡v¼Ò¦¡¶}±ÒÀɮ׮ɡA¸ÓÀÉ®×¥²¶·¬O¤w«Ø¥ß§¹¦¨¡A¤£¥i¬O¤£¦s¦bªºÀɮסA§_«h·|µo¥Í¡ufailed to create stream: No such file or directory¡vªº¿ù»~¡A¦p¤U¹Ï¡G

¹Ï6-17  ¿ù»~¡A±ý¶}±Ò¤£¦s¦bªºÀɮסC

µù2¡G
­Y±z§Æ±æ¶}±ÒªºÀɮפ£¦s¦b®É¡A¯à°÷¦Û°Ê«Ø¥ß¸ÓÀɮסA½Ð¯S§Oª`·N¥Ø¿ýªº¨Ï¥ÎÅv­­¡I¹w³]¬O¤£¤¹³\¡u¼g¤J¡v°Ê§@¡]¤£¯à«Ø¥ßÀɮסA§ïÅÜÀɮפº®e¡^¡A¦]¦¹·|¦³¡ufailed to create stream: Permission denied¡vªº¿ù»~¡C

¹Ï6-18  ¿ù»~¡A¤£¤¹³\«Ø¥ßÀɮסC

¦bWindow 2000¤¤¡A±zÀ³¸Ó¦b¦Û°Ê«Ø¥ßÀɮשҦbªº¥Ø¿ý¹Ï¥Ü¤W«ö¤U·Æ¹«¥kÁä¡A¿ï¨ú¡u¤º®e¡v->ÂI¿ï¡u¦w¥þ¡v­¶ÅÒ->¡u¦WºÙ¡vÄæ¦ì¤¤¿ï¨ú¡yUsers¡z¶µ¥Ø->¡yÅv­­¡zÄæ¦ì¸Ì¡A§â¡u­×§ï¡v¡B¡uŪ¨ú¡v»P¡u¼g¤J¡v³o¤T­Ó¶µ¥Øªº¡y¤¹³\¡z®Ö¨ú°_¨Ó¡G

¹Ï6-19 ¦w¥þ©Ê³]©w¡C

¸g¹L¥H¤W³]©w«á¡A±z´N¥i¥H¦b«ü©wªº¥Ø¿ý¤U¡A«Ø¥ßÀɮסA­×§ïÀɮסA»PŪ¨úÀɮ׸ê®Æ¤F¡I­Y¡u¦WºÙ¡vÄæ¦ì¤¤¨S¦³¡yUsers¡z¶µ¥Ø«h¥i«ö¤U¡u·s¼W¡v«ö¶s¨Ó¼W¥[¨Ï¥ÎªÌ¶µ¥Ø¡G

¹Ï6-20  ¼W¥[¨Ï¥ÎªÌ¡C

¦bWindow XP¤¤¡A¡u¤º®e¡v¶µ¥Ø¤¤¹w³]¬O¨S¦³¡u¦w¥þ©Ê¡v³o­Ó­¶ÅÒªº¡A¦b³]©w¥Ø¿ýÅv­­®É«h»Ý¥ý±N¡u¦w¥þ©Ê¡v­¶ÅÒÅÜ¥X¨Ó¡C
ÂI¿ï¡u§Úªº¹q¸£¡v>¤u¨ã >¸ê®Æ§¨¿ï¶µ¡G

¹Ï6-21  ¸ê®Æ§¨¿ï¶µ³]©w¡C

¦b¡u¸ê®Æ§¨¿ï¶µ¡vµøµ¡¤¤¿ï¨ú¡yÀ˵ø¡z­¶ÅÒ >§ä¨ì¡u¨Ï¥Î²©öÀɮצ@¥Î¡]«Øij¨Ï¥Î¡^¡v³o­Ó¶µ¥Ø¡A¨Ã¨ú®ø³o­Ó¶µ¥Øªº®Ö¨ú¡A³o¼Ë¤@¨Ó¡A¸ê®Æ§¨ªº¡u¤º®e¡vµøµ¡¤¤´N¦³¡u¦w¥þ©Ê¡v³o­Ó­¶ÅÒ¤F¡G

¹Ï6-22  ¨ú®ø¡u¨Ï¥Î²©öÀɮצ@¥Î¡]«Øij¨Ï¥Î¡^¡v¶µ¥Ø¡C

¦b¡u¦w¥þ©Ê¡v­¶ÅÒªº¡y¸s²Õ©Î¨Ï¥ÎªÌ¦WºÙ¡zÄæ¦ì¤¤¿ï¨ú¡yUsers¡z¶µ¥Ø >¡yUsersªºÅv­­¡zÄæ¦ì¸Ì¡A§â¡u­×§ï¡v¡B¡uŪ¨ú¡v»P¡u¼g¤J¡v³o¤T­Ó¶µ¥Øªº¡y¤¹³\¡z®Ö¨ú°_¨Ó¡G

¹Ï6-23  ¨ú®ø¡u¨Ï¥Î²©öÀɮצ@¥Î¡]«Øij¨Ï¥Î¡^¡v¶µ¥Ø¡C

¸g¹L¥H¤W³]©w«á¡A±z´N¥i¥H¦bwindow XP§@·~¨t²Î¤¤¡A©ó«ü©wªº¥Ø¿ý¤U¡A«Ø¥ßÀɮסA­×§ïÀɮסA»PŪ¨úÀɮ׸ê®Æ¤F¡C
fopen()¨ç¼Æ¨Ã¤£­­©w¶}±Ò¥»¦aºÝÀɮסA¥ç¥i¶}±Ò»·ºÝÀɮסA¨Ò¦p¡G
  1. <?
  2. $myfile=fopen("http://www.twbts.com/test.txt","r");
  3. $hisfile=fopen("http://www.twbts.com/","w+");  //µù
  4. $yourfile=fopen("ftp://user:[email protected]/","r");
  5. ?>
½Æ»s¥N½X
µù¡G¥HHTTP ºô§}©Ò«ü©wªºÀÉ®×¥u¯à¶}±Ò¦¨°ßŪ¼Ò¦¡¡A¦pªG¶}±Ò¦¨¼g¤J¼Ò¦¡«h·|³y¦¨¿ù»~¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ¡i°µ¤Hªº¶}©l¡j¨C¤@¤Ñ³£¬O¬G¤Hªº¶}©l¡A¨C¤@­Ó®É¨è³£¬O¦Û¤vªºÄµ±§¡C
ªð¦^¦Cªí ¤W¤@¥DÃD