19
Read and Write I. File Input & Output II. Classes

I/O PHP Files and classes

Embed Size (px)

Citation preview

Page 1: I/O PHP Files and classes

Read and Write

I. File Input & Output

II. Classes

Page 2: I/O PHP Files and classes

1- Open connection to a file.

2- Process R/W Operation.

3- Close Connection.

You specify the operation (read or write)

when opening a file.

Built in PHP Library

Page 3: I/O PHP Files and classes

In order to read or write to a file , you

have to get the write permissions.

Permission is something to set on the

server operating system.

Permissions

Page 4: I/O PHP Files and classes

Open file function return a handle ,

represents a connection to the opened

file.

o This is called resource data type.

fopen need to specify name and path

(Rel/Abs) of the file and red or write mode.

Use forward slashes ”/” of both Unix &

Windows.

fopen()

Page 5: I/O PHP Files and classes

Is used to write the contents of a string to

file open for writing.

o File handle is one of it`s parameters.

Return number of characters written on

success, otherwise return false.

Fputs() is an alias.

R+ is the access mode of writing.

fwrite()

Page 6: I/O PHP Files and classes

$handle=fopen($path ,’ r+ ’)

$write=fwrite( $handle , $string )

If($write){ echo “Success”}File pointer at the end of string

// Read about access modes

fwrite()

Get file path dynamically if

file name = query.txt

Page 7: I/O PHP Files and classes

Data is encoded using URL-encoding by default.

Data included in the http body.

The form data should be of the content type

Upload file using http post

By setting the encrypt

attribute of html form

Multipart/form-data?

Page 8: I/O PHP Files and classes

“Multipart/form-data”

<input type = “file” name”upload”>

Page 9: I/O PHP Files and classes
Page 10: I/O PHP Files and classes
Page 11: I/O PHP Files and classes

Real worldClasses

Page 12: I/O PHP Files and classes
Page 13: I/O PHP Files and classes

Refers to an instance of a class car().

Creating an object called

Instantiation

$mycar=new car();

Objects

Page 14: I/O PHP Files and classes

Difference between object and class

Page 15: I/O PHP Files and classes

objects

Class

Car-color

-model-top-speed

Red,Volovo,220 k/h

White,Retmo,

160 k/h

Difference between object and class

Page 16: I/O PHP Files and classes

Turn Class to an objectClass name:car

$mycar=new car();

Page 17: I/O PHP Files and classes

Turn Class to an objectClass name:car

Class car{Public $color;

Public $model;

Public $top_speed;

}

$mycar=new car();

$mycar->color=‘red’

$mycar->model=‘volvo’

$color=$mycar->color;

Page 18: I/O PHP Files and classes

PHP Time Stamp

1439938978 seconds since

Jan 01 1970. (UTC)

Page 19: I/O PHP Files and classes

What is the Unix time stamp?

The Unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC

http://php.net/manual/en/function.time.php