lecture28

lecture28 - PIC 40A Lecture 28: PHP File I/O, Databases,...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 40A Lecture 28: PHP File I/O, Databases, MySQL
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PHP File I/O • PHP has the ability to open, read, and write files on the server using both FTP and HTTP protocols • We will concern ourselves only with plain text files, not binary files.
Background image of page 2
Opening a file • We need a PHP resource called a file handle to reference a file on the server • To open a text file on the server, use PHP function fopen($filepath, $fileop) $filepath- string path of the file on the server to open $fileop- string specifying the operations to perform on the file
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Opening a file example $filehandle = fopen("data.txt", "r") or die("File can't be opened"); die terminates the PHP script and displays the given error message
Background image of page 4
File Use Indicators ( $fileop ) "r" read only. file pointer initialized to beginning of the file "r+" read and write existing file. file pointer initialized to beginning of the file. if read operator precedes a write, data is written where read left the file pointer "w" write only. file pointer initialized to beginning of the file. creates file if does not exist "w+" same as r+ but creates file if does not exist. "a" appends. write only. file pointer at end of the file. creates file if does not exist "a+" appends. read and write a file. file pointer at end of the file. creates file if does not exist
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Reading from a file use fread($filehandle,$numbytesread) eg $bytes_to_read = filesize ("data.txt"); $file_string = fread ($filehandle, bytes_to_read);
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/15/2010 for the course PIC 40A taught by Professor Ouellette during the Winter '10 term at UCLA.

Page1 / 26

lecture28 - PIC 40A Lecture 28: PHP File I/O, Databases,...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online