Feem ntau ntawm cov ntsiab lus ntawm cov khoom siv hauv web niaj hnub no yog tsim los ntawm cov ntawv sau server-sab. Tab sis hauv txoj kev no, feem ntau cov ntaub ntawv xov xwm raug tso tawm kom pom (nplooj ntawv nplooj, nplooj ntawv style, daim ntawv pov thawj). Cov duab, suab paj nruag, yeeb yaj kiab, khaws cia, raws li txoj cai, yog nyob ntawm tus neeg rau zaub mov rau hauv cov ntaub ntawv ntawm cov ntaub ntawv zoo li qub. Txawm li cas los xij, qee zaum nws yuav tsim nyog los tsim cov ntaub ntawv zoo sib xws siv cov ntawv sau. Yog li, yog tias koj xav tau muab cov duab zoo li qub, koj tuaj yeem tso nws ntxig rau hauv tsab ntawv.
Tsim nyog
lub peev xwm tsim lossis hloov kho cov ntawv sau server
Cov Lus Qhia
Kauj ruam 1
Ntxig cov duab no rau hauv cov ntawv sau ua cov ntawv nyeem, uas yog ib feem ntawm qhov program code. Siv cov ntaub ntawv yooj yim tshaj plaws thiab cov qauv tsim qauv syntactic. Qhov kev xaiv feem ntau yog txiav txim siab los ntawm lub peev xwm ntawm cov lus programming siv. Yog li, feem ntau nws yooj yim los ntxig ib daim duab rau hauv tsab ntawv raws li cov cim kev ib txwm muaj, cov ntsiab lus ntawm uas yog cov ntaub ntawv duab encoded nrog algorithm zoo li Base64. Hauv PHP nws yuav zoo li qhov no (2x2 pixel.
Kauj ruam 2
Npaj cov duab rau cov zis. Txiav txim tawm cov ntaub ntawv qub yog tsim nyog. Koj yuav tsum tau txais tsis zoo uas muaj cov ntaub ntawv binary ntawm daim duab. Piv txwv li, hauv PHP, txiav txim siab cov hlua muab rau hauv thawj kauj ruam yuav zoo li no: $ text = base64_decode ($ str);
Kauj ruam 3
Nyob rau hauv lub header ntawm tus neeg rau zaub mov HTTP teb, ntxiv ib daim teb uas muaj cov ntaub ntawv ntawm qhov ntev ntawm cov lus teb lub cev (qhov loj me ntawm cov duab pom). Txheeb xyuas qhov txiav txim siab siv cov haujlwm los yog cov hau kev rov qab qhov ntev ntawm kev tuav, hlua, thiab lwm yam. Piv txwv li: header ('Ntsiab lus-ntev:'.suav tawm ($ ntawv));
Kauj ruam 4
Ntxiv ib daim teb rau HTTP teb lub taub hau ntawm lub server qhia txog mime-hom ntawm cov ntsiab lus hloov pauv. Piv txwv li: header ('Cov ntsiab lus-hom: duab / gif'); Cov hom ntsiab lus yuav tsum paub (txiav txim siab raws hom qauv ntawm daim duab qub).
Kauj ruam 5
Yog tias koj xav yuam kom cov duab tau txais kev cawm dim es tsis txhob tso tawm los ntawm lub browser, ntxiv rau qhov tsim nyog rau cov lus teb header: header ("Content-Disposition: attachment; filename = my_image.gif");
Kauj Ruam 6
Yog tias koj xav kom tsis txhob khaws cia cov duab los ntawm lub browser, nkag mus rau Pragma thiab cache-Control teb nrog cov txiaj ntsig tsim nyog hauv cov lus teb HTTP: header ("Pragma: no-cache"); header ("Cache-Tswj: tsis muaj -cache, yuav tsum-rov tsim kho, tsis muaj khw muag khoom "); header (" Cache-Tswj: kev kuaj xyuas = 0, kuaj tom qab = 0 ", tsis tseeb); Nws tseem tsim nyog muab cov hnub ntawm kev hloov kho zaum kawg thiab tas sij hawm hnub tim lub peev txheej. Hauv qhov xwm txheej no, qhov thib ob ntawm lawv yuav tsum yog tom qab: header ("Expire: Mon, 4 Jan 1993 00:00:01 GMT"); header ("Last-Modified:".gmdate ("D, d MYH: i: s ")." GMT ");
Kauj Ruam 7
Ua lub cev ntawm tus neeg rau zaub mov HTTP teb, uas yog cov ntaub ntawv duab. Siv cov haujlwm lossis cov qauv ntawm cov khoom siv uas muab cov khoom ntawm cov ntaub ntawv binary tsis muaj kev ua haujlwm ntxiv. Piv txwv li: printf ('% s', $ ntawv);