www.Hacking-Romania.com
Hacking, gaby hacker team, programe hack, radmin hack, hi5 hack, hack the west, hacking romania, hacking stuff, hacking tools, 1 hack, 1st hacks, 2 hack, 2 hacks, 3 hack, 3 hacks, 3000 hack, 3004 hack, 4 hack, 4 hacks, 55 hack, 6 hack, 6 hacks, 7 hack, 7 hacks, 9 hack, 9dragons hack, a hack, adventure quest hack, aim hack, alz hack, and hacks, best hack, blue hack, bots hack, bots hacks, buy hack, cabal online hack, chaos hacks, cheat engine hack, cheat hack, cheats and hacks, cheats hacks, city hack, club hack, combo hack, conquer hacks, conquer online hack, conquer online hacks, conquer speed hack, conquiztador hack, counter strike 1.6 hack, damage hack, de hack, download hack, download hack for, dragonfable hack, dragonfable hacks, drakkarious hack, exp hack, flyff hack, free hack, free hacks, game hack, game hacks, garena exp hack, gladiatus hack, gm hack, gold hack, gunz hack, hack, hack 5, hack a pc, hack a site, hack a website, hack blog, hack conquer, hack counter strike, hack crack, hack cs, hack cs 1.6, hack dvd, hack email, hack forum, hack hunter, hack id, hack info, hack it, hack mess, hack muonline, hack net, hack password, hack passwords, hack pc, hack pdf, hack programs, hack site, hack sites, hack soft, hack software, hack team, hack the game, hack this, hack website, hack windows xp, hack world, hack xp, hacked, hacking, hacking game, hacking programs, hacking software, hacking tutorials, hacks, how hack, how to hack, icon hack, last chaos hack, last chaos hacks, life hack, lineage 2 hack, lineage 2 hacks, linux hack, lvl hack, maplestory hacks, mobile hack, multi hack 3.0, mybrute hack, naruto arena hack, naruto arena hacks, one hit kill hack, online hacks, perfect world hacks, pool hack, programe hack, resolution hack, resource hack, roll hack, royal hack, silkroad hack, source hack, speed hack, speed hacks, super hack, the west hack, warrock hack, warrock hacks, web hack, xpango hack, lockerz forum
Lista Forumurilor Pe Tematici
www.Hacking-Romania.com | Reguli | Inregistrare | Login

POZE WWW.HACKING-ROMANIA.COM

Nu sunteti logat.
Nou pe simpatie:
MicheleC
Femeie
19 ani

cauta Barbat
26 - 68 ani
www.Hacking-Romania.com / Tutoriale PHP / Lucrul cu fiesiere in php  
Autor
Mesaj Pagini: 1
danuhack
MEMBRU SPECIAL

Din: '"test
Inregistrat: acum 16 ani
Postari: 447
Lucrul cu fisiere
Folosind PHP-ul se pot executa anumite operatii asupra fisierelor aflate pe server cum ar fi:
fopen() = deschide fisierul indicat
fclose() = inchide fisierul
fread() = citeste continutul fisierului
fwrite() = scrie in fisier
filesize() = indica dimensiunea fisierului
Deschiderea fisierelor
Sintaxa functiei fopen() este:

fopen(param1, param2);
param1 = fisierul, calea catre fisier sau adresa fisierului care va fi deschis
param2 = modul in care va fi deschis fisierul, si poate avea valorile:

r = fisier deschis doar pentru citire
r+ = fisier deschis doar pentru citire si scriere
w = fisier deschis doar pentru scriere
w+ = fisier deschis pentru citire si scriere iar daca nu exista fisierul il creza
a = fisier deschis pentru adaugare la sfarsit
a+ = fisier deschis adaugare la sfarsit iar daca nu exista fisierul il creza
t = fisier deschis in mod text
b = fisier deschis in mod binar
sau combinatii ale acestora.

Citirea fisierelor
Sintaxa functiei fread() este:

$filename="proba.txt";
$handle=fopen($filename, "r");
$contents=fread($handle, filesize($filename));
variabila $handle va fi folosita ulterior si in alte functii

Scrierea in fisiere
Sintaxa functiei fwrite() este:

fwrite($handle, "continut ce va fi scris in fisier");
Verificarea drepturilor de acces asupra fisierului
Sintaxa functiei is_writable este:
is_writable($filename);
returneaza TRUE daca se poate si FALSE daca nu se poate scrie in fisier

Inchiderea fisierului
Sintaxa functiei fclose() este:
fclose($handle);
Folosind aceste functii de baza putem incerca cateva exemple simple.

Exemplu: se verifica dreptul de scriere in fisier. Primul pas este crearea fisierului proba.txt apoi se verifica exemplul care va returna mesajul Acces interzis scrierii in fisier. Se modifica drepturile asupra fisierului conform Q5 din FAQ adaugand scrierea. Se verifica iar exemplul care va returna mesajul Acces permis scrierii in fisier.
<?php
$filename="proba.txt";
if(is_writable($filename)) { //se verifica dreptul de scriere in fisier
echo "Acces permis scrierii in fisier";
} else {
echo "Acces interzis scrierii in fisier";
}
?>
Exemplu: adaugam exemplului anterior verificarea deschiderii fisierului.
<?php
$filename="proba.txt";
if(is_writable($filename)) { //se verifica dreptul de scriere in fisier
if(!$handle=fopen($filename, 'a')) { //se verifica deschiderea fisierului
echo "Fisierul <b>".$filename."</b> nu poate fi deschis";
exit; //se incheie executia scriptului
}
echo "Fisierul <b>".$filename."</b> poate fi deschis";
} else {
echo "Acces interzis pentru scriere in fisier";
}
?>
Exemplu: adaugam exemplului anterior scrierea in fisier si tiparirea continutului sau
<?php
$filename="proba.txt";
if(is_writable($filename)) { //se verifica dreptul de scriere in fisier
if(!$handle=fopen($filename, 'a')) { //se verifica deschiderea fisierului
echo "Fisierul <b>".$filename."</b> nu poate fi deschis";
exit; //se incheie executia scriptului
}
if(fwrite($handle, date("j-n-Y g:ia")."\r\n")===FALSE) { //testeaza daca se poate scrie in fisier
die ("Nu se poate scrie in ".$filename.""); //iesire
}
fclose($handle);
$matrice=file($filename); //se citeste continutul fisierului si se stocheaza intr-o matrice
foreach ($matrice as $cheie =>$valoare) {
echo $valoare."<br>"; //printeaza cate o valoare pe un rand
}
} else {
echo "Acces interzis pentru scriere in fisier";
}
?>

Modificat de danuhack (acum 15 ani)


_______________________________________
[img]http://i220.photobucket.com/albums/dd214/CatalynCN/bnr_bancnota_zero_0_lei_ron_1266581.jpg[/img]

pus acum 15 ani
   
Pagini: 1  

Mergi la