Jak Začít?

Máš v počítači zápisky z přednášek
nebo jiné materiály ze školy?

Nahraj je na studentino.cz a získej
4 Kč za každý materiál
a 50 Kč za registraci!




Soubory a data

PDF
Stáhnout kompletní materiál zdarma (1.95 MB)

Níže je uveden pouze náhled materiálu. Kliknutím na tlačítko 'Stáhnout soubor' stáhnete kompletní formátovaný materiál ve formátu PDF.

Soubory a data

Martin Klíma

Ukládání

dat do souborů

Náhradní způsob ukládávní dat

Hlavní je databáze

Data v paměti -> serializace -> zápis do souboru

Data v souboru -> deserialiace -

> data v paměti

Operace se soubory

Mnoho funkcí, viz 
http://php.net/manual/en/ref.filesystem.php

Vybereme jen základní

resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )

ukázka

$handle = fopen("c:\\folder\\resource.txt", "r"); // otevření souboru pro čtení

$handle = fopen("c:\\folder\\resource.txt", „w+"); // otevření souboru pro čtení i zápis

$handle = fopen("c:\\folder\\resource.txt", „x+"); // vytvoření souboru a následně 

jeho otevření pro čtení i zápis

Módy otevření souboru

mode

Description

'r'

Open for reading only; place the file pointer at the beginning of the file. 

'r+'

Open for reading and writing; place the file pointer at the beginning of the file. 

'w'

Open for writing only; place the file pointer at the beginning of the file and truncate the file 
to zero length. If the file does not exist, attempt to create it. 

'w+'

Open for reading and writing; place the file pointer at the beginning of the file and truncate 
the file to zero length. If the file does not exist, attempt to create it. 

'a'

Open for writing only; place the file pointer at the end of the file. If the file does not exist, 
attempt to create it. In this mode, fseek() has no effect, writes are always appended. 

'a+'

Open for reading and writing; place the file pointer at the end of the file. If the file does not 
exist, attempt to create it. In this mode, fseek() only affects the reading position, writes are 
always appended. 

'x'

Create and open for writing only; place the file pointer at the beginning of the file. If the file 
already exists, the fopen() call will fail by returning FALSE and generating an error of level 
E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying 
O_EXCL|O_CREAT flags for the underlying open(2) system call. 

Témata, do kterých materiál patří