PHP Seminar: Submitted By, S. Yogalakshmi
PHP Seminar: Submitted By, S. Yogalakshmi
Submitted By,
S.
Yogalakshmi
Topics to be discussed..
Arrays
Include and require statement
Database functions
File Handling
File Handling
Manipulating Files
functions for creating, reading, uploading,
and editing files
readfile()
readfile() function reads a file and writes it to
the output buffer
open up a file and read its contents
fopen()
$myfile = fopen("webdictionary.txt", "r") or
die("Unable to open file!");
fclose()
The function is used to close an open file.
fread()
The fread() function reads from an open file.
first parameter contains the name of the file
second parameter specifies the maximum
number of bytes to read.
fgets()
read a single line from a file
Ex. $myfile = fopen("web.txt", "r") or die("Unable
to
open file!");
echo fgets($myfile);
fgetc()
function is used to read a single character from a file.
feof()
The feof() function checks if the "end-of-file" (EOF)
has been reached
useful for looping through data of unknown length.
Example,
$myfile = fopen("webdictionary.txt", "r") or die("Unable to
open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
fwrite()
function is used to write to a file.
Ex.
$myfile = fopen("newfile.txt", "w") or
die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
File Upload
upload files to the server
Rules to follow for the HTML form
above:
Make sure that the form uses
method="post"
The form aneeds the following attribute:
enctype="multipart/form-data". It
specifies which content-type to use
when submitting the form
upload script
is an associate double dimension array and
keeps all the information related to uploaded
file
$_FILES['file']['tmp_name']-the uploaded file in
the temporary directory on the web server.
$_FILES['file']['name'] -the actual name of the
uploaded file.
$_FILES['file']['size'] -the size in bytes of the
uploaded file.
$_FILES['file']['type'] -the MIME type of the
uploaded file.
$_FILES['file']['error'] -the error code
associated with this file upload.