i/o php files and classes
TRANSCRIPT
Read and Write
I. File Input & Output
II. 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
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
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()
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()
$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
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?
“Multipart/form-data”
<input type = “file” name”upload”>
Real worldClasses
Refers to an instance of a class car().
Creating an object called
Instantiation
$mycar=new car();
Objects
Difference between object and class
objects
Class
Car-color
-model-top-speed
Red,Volovo,220 k/h
White,Retmo,
160 k/h
Difference between object and class
Turn Class to an objectClass name:car
$mycar=new car();
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;
PHP Time Stamp
1439938978 seconds since
Jan 01 1970. (UTC)
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