File handling
PAPER NAME : PROGRAMMING IN PHP
STAFF NAME : MS.V.SHANTHI M.SC,M.PHIL,M,TECH,PGDCA.
CLASS : III BCA
SEMESTER : VI
FILE HANDLING:
 This chapter discusses file handling using PHP. Storing data
on the server is especially powerful in web applications,
because it allows you to make data “persist”-that is, stick
around between page accesses. Blogs, guest books, feedback
pages- all are possible when you work with files on the server.
 There’s a lot of PHP technology coming up in this chapter,
starting with opening files .
EXAMPLE:
<html>
<head>
<title>
Reading from a file
</title>
<body>
<h1>
Reading from a file
</h1>
<?php
$handle= fopen(“file.txt”, “r”);
while(!foef($handle)){
.
.
.
}
?>
</body>
</html>
READING A FILE INTO AN ARRAY
WITH FILE:
 You can use the file function to read a file into an array all at
ones; each line becomes an element in the array. Here’s how to
use the file function;
file(file name [, use _ include_ path[,context]])
READING AND WRITING BINARY
FILES:
 You can write binary data with f1write, and read it with fread,
but it takes a little work. You can pack binary data into strings
using the pack function, and unpack binary data using the
unpack function.
Example, phpwritebinary.php, that writes the number 512 to a file
in binary(not string)format. If starts by opening the file for
binary writing like this;
<?php
$number=512;
$handle= fopen(“data.dat”, “wb”);
.
.
DELETING FILES WITH UNLINK:
 Want to delete a file? You can do that with the unlink function:
unlink(filename[,context])
 Here, filename is the name of the file, and context is an
optional context. This function returns TRUE if the file was
deleted, FALSE otherwise.
 You can find an example in phpunlink.php. If the code is
successful in deleting copy.txt, it says so:
<?php
if(unlink(“copy.txt”)){
echo “Deleted the file.”;
}
.
.
LOCKING FILES:
 In a multiuser environment, such as web server, multiple users
may be accessing your scripts at the same time,which means
multiple copies of the same script can operate at the same time.
If your script(s) accesses files, there may be a conflict as to
scripts, or to copies of the same script, tries to write to the same
file at the same time. To fix that, use the file locking function.
 Here, handle is the handle of the file you want to lock, and
operation is one of these:
To attain a shared lock(reader), set operation to LOCK_SH.
To attain an exclusive lock(writer), set operation to LOCK_EX.
To release a lock, set operation to LOCK_UN.
FILE HANDLING OPERATIONS:
 File handling starts with creating a file, reading its content,
writing into a file to conjoin data into an existing file and
finally closing the file. PHP provides predefined functions for
all these operations.
1. Create a file : fopen()
2. Open a file : fopen()
3. Read a file : fread()
4. Write to a file : fwrite()
5. Append to a file: fwrite()
6. Close a file : fclose()
7. Delete a file : unlink()
DATABASE:
What is a database?
 We’ll take a lock at what makes a database here briefly(and if
you are already familiar with databases, tables, and so on , you
can naturally skip this intro).
 Databases organise data for easy access and use by
programs.the most popular database construct is the table and
we’ll take a lock at tables here. Say, foe example that you’re
teaching PHP to a class of students and want to keep track of
their scores. You might create a table with two columns, Name
and Grade:
PHP SUPPORTED DATABASES:
Adabas Ingres Oracle
dBase InterBase Ovrimos
Empress FrontBase PostgreSQl
FilePro mSQL Solid
Hyperwave Direct MS-SQL Sybase
IBM DB2 MS-SQL Velocis
Informix ODBC Unix dbm
Accessing the database in PHP:
 When you install PHP, you can select from a number of
protraction. To install support for My SQL, click the
extension node in the installer to open that node and select the
My SQL node to install that extension. Your PHP installation
may have already been installed with My SQL support most
installation on web servers are.
 The My SQL support in PHP consists of a number of
functions you can call to interact with My SQL, and here they
are:
 My sql affected rows Get the number of rows affected by the
previous MySQL operation.
 My sql change user Change the logged-in user.
 My sql client encoding Return the name of the current
character set.
 My sql close Close a MySQL connection.
 My sql connect Open a connection to a MySQL Server.
 My sql create db Create a MySQL database.
 My sql data seek Seek data in the database.
 My sql db name Get the name of the database.
 My sql db query Send a My SQL query.

More Related Content

PPT
Spider Course Day 1
ODP
Php File Upload
PPTX
Uploading a file with php
PPTX
Connecting to my sql using PHP
PPTX
PHP web design
PPTX
Php basics
PPTX
PHP Hypertext Preprocessor
PDF
Joy of Unix
Spider Course Day 1
Php File Upload
Uploading a file with php
Connecting to my sql using PHP
PHP web design
Php basics
PHP Hypertext Preprocessor
Joy of Unix

What's hot (20)

PPT
Installation of OpenBiblio on Windows XP using EasyPHP
PPTX
Backup Restore Migration Wordpress hosted on 1and1
PPT
Slide 1 - The University of Mississippi
PPTX
Lamp introduction in Fedora
ODP
PHP BASIC PRESENTATION
PPTX
File upload php
PDF
Apache Server Tutorial
PPT
Class 1 - World Wide Web Introduction
PPT
Installation of Openbiblio using Easyphp
PPTX
Introduction to Drupal CMS
PDF
Securing the Apache web server
PPT
Apache Web Server Setup 2
PDF
Chp 08 php (shared)
PPTX
Encrypting/Decrypting mule
PPTX
File Uploading in PHP
PPT
Apache Web Server Setup 3
PPT
File Upload
PPTX
PHP in one presentation
PPT
Apache
PPTX
Apache web service
Installation of OpenBiblio on Windows XP using EasyPHP
Backup Restore Migration Wordpress hosted on 1and1
Slide 1 - The University of Mississippi
Lamp introduction in Fedora
PHP BASIC PRESENTATION
File upload php
Apache Server Tutorial
Class 1 - World Wide Web Introduction
Installation of Openbiblio using Easyphp
Introduction to Drupal CMS
Securing the Apache web server
Apache Web Server Setup 2
Chp 08 php (shared)
Encrypting/Decrypting mule
File Uploading in PHP
Apache Web Server Setup 3
File Upload
PHP in one presentation
Apache
Apache web service
Ad

Similar to File handling (20)

PPTX
4-chapter-File & Directores.pptx debre CTABOUR UNIversit
DOCX
CONTENT MANAGEMENT SYSTEM
PPT
GTU MCA PHP Interview Questions And Answers for freshers
PDF
PHP Basics
PDF
Php interview-questions and answers
PPT
Php basics
PPTX
Php Unit 1
PDF
Php Interview Questions
PDF
Php Applications with Oracle by Kuassi Mensah
PDF
Essential Guide To Php For All Levels O Adeolu
PDF
Wamp & LAMP - Installation and Configuration
PDF
4 Basic PHP
PPT
Flyr PHP micro-framework
PPT
Php intro
PPT
Php intro
PPT
Php intro
PPTX
Apache web server
PDF
PHP Unit-1 Introduction to PHP
PDF
XOOPS 2.5.x Debugging with FirePHP/FireBug
4-chapter-File & Directores.pptx debre CTABOUR UNIversit
CONTENT MANAGEMENT SYSTEM
GTU MCA PHP Interview Questions And Answers for freshers
PHP Basics
Php interview-questions and answers
Php basics
Php Unit 1
Php Interview Questions
Php Applications with Oracle by Kuassi Mensah
Essential Guide To Php For All Levels O Adeolu
Wamp & LAMP - Installation and Configuration
4 Basic PHP
Flyr PHP micro-framework
Php intro
Php intro
Php intro
Apache web server
PHP Unit-1 Introduction to PHP
XOOPS 2.5.x Debugging with FirePHP/FireBug
Ad

Recently uploaded (20)

PPTX
DRUGS USED FOR HORMONAL DISORDER, SUPPLIMENTATION, CONTRACEPTION, & MEDICAL T...
PDF
Empowerment Technology for Senior High School Guide
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
PDF
English Textual Question & Ans (12th Class).pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
Climate and Adaptation MCQs class 7 from chatgpt
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
CRP102_SAGALASSOS_Final_Projects_2025.pdf
PPTX
Module on health assessment of CHN. pptx
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PDF
semiconductor packaging in vlsi design fab
PDF
Literature_Review_methods_ BRACU_MKT426 course material
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
Computer Architecture Input Output Memory.pptx
PDF
IP : I ; Unit I : Preformulation Studies
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
DRUGS USED FOR HORMONAL DISORDER, SUPPLIMENTATION, CONTRACEPTION, & MEDICAL T...
Empowerment Technology for Senior High School Guide
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
English Textual Question & Ans (12th Class).pdf
My India Quiz Book_20210205121199924.pdf
Climate and Adaptation MCQs class 7 from chatgpt
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
CRP102_SAGALASSOS_Final_Projects_2025.pdf
Module on health assessment of CHN. pptx
AI-driven educational solutions for real-life interventions in the Philippine...
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
semiconductor packaging in vlsi design fab
Literature_Review_methods_ BRACU_MKT426 course material
Cambridge-Practice-Tests-for-IELTS-12.docx
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
Introduction to pro and eukaryotes and differences.pptx
Computer Architecture Input Output Memory.pptx
IP : I ; Unit I : Preformulation Studies
Share_Module_2_Power_conflict_and_negotiation.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf

File handling

  • 2. PAPER NAME : PROGRAMMING IN PHP STAFF NAME : MS.V.SHANTHI M.SC,M.PHIL,M,TECH,PGDCA. CLASS : III BCA SEMESTER : VI
  • 3. FILE HANDLING:  This chapter discusses file handling using PHP. Storing data on the server is especially powerful in web applications, because it allows you to make data “persist”-that is, stick around between page accesses. Blogs, guest books, feedback pages- all are possible when you work with files on the server.  There’s a lot of PHP technology coming up in this chapter, starting with opening files .
  • 4. EXAMPLE: <html> <head> <title> Reading from a file </title> <body> <h1> Reading from a file </h1> <?php $handle= fopen(“file.txt”, “r”); while(!foef($handle)){ . . . } ?> </body> </html>
  • 5. READING A FILE INTO AN ARRAY WITH FILE:  You can use the file function to read a file into an array all at ones; each line becomes an element in the array. Here’s how to use the file function; file(file name [, use _ include_ path[,context]])
  • 6. READING AND WRITING BINARY FILES:  You can write binary data with f1write, and read it with fread, but it takes a little work. You can pack binary data into strings using the pack function, and unpack binary data using the unpack function. Example, phpwritebinary.php, that writes the number 512 to a file in binary(not string)format. If starts by opening the file for binary writing like this; <?php $number=512; $handle= fopen(“data.dat”, “wb”); . .
  • 7. DELETING FILES WITH UNLINK:  Want to delete a file? You can do that with the unlink function: unlink(filename[,context])  Here, filename is the name of the file, and context is an optional context. This function returns TRUE if the file was deleted, FALSE otherwise.  You can find an example in phpunlink.php. If the code is successful in deleting copy.txt, it says so: <?php if(unlink(“copy.txt”)){ echo “Deleted the file.”; } . .
  • 8. LOCKING FILES:  In a multiuser environment, such as web server, multiple users may be accessing your scripts at the same time,which means multiple copies of the same script can operate at the same time. If your script(s) accesses files, there may be a conflict as to scripts, or to copies of the same script, tries to write to the same file at the same time. To fix that, use the file locking function.  Here, handle is the handle of the file you want to lock, and operation is one of these: To attain a shared lock(reader), set operation to LOCK_SH. To attain an exclusive lock(writer), set operation to LOCK_EX. To release a lock, set operation to LOCK_UN.
  • 9. FILE HANDLING OPERATIONS:  File handling starts with creating a file, reading its content, writing into a file to conjoin data into an existing file and finally closing the file. PHP provides predefined functions for all these operations. 1. Create a file : fopen() 2. Open a file : fopen() 3. Read a file : fread() 4. Write to a file : fwrite() 5. Append to a file: fwrite() 6. Close a file : fclose() 7. Delete a file : unlink()
  • 10. DATABASE: What is a database?  We’ll take a lock at what makes a database here briefly(and if you are already familiar with databases, tables, and so on , you can naturally skip this intro).  Databases organise data for easy access and use by programs.the most popular database construct is the table and we’ll take a lock at tables here. Say, foe example that you’re teaching PHP to a class of students and want to keep track of their scores. You might create a table with two columns, Name and Grade:
  • 11. PHP SUPPORTED DATABASES: Adabas Ingres Oracle dBase InterBase Ovrimos Empress FrontBase PostgreSQl FilePro mSQL Solid Hyperwave Direct MS-SQL Sybase IBM DB2 MS-SQL Velocis Informix ODBC Unix dbm
  • 12. Accessing the database in PHP:  When you install PHP, you can select from a number of protraction. To install support for My SQL, click the extension node in the installer to open that node and select the My SQL node to install that extension. Your PHP installation may have already been installed with My SQL support most installation on web servers are.
  • 13.  The My SQL support in PHP consists of a number of functions you can call to interact with My SQL, and here they are:  My sql affected rows Get the number of rows affected by the previous MySQL operation.  My sql change user Change the logged-in user.  My sql client encoding Return the name of the current character set.  My sql close Close a MySQL connection.  My sql connect Open a connection to a MySQL Server.  My sql create db Create a MySQL database.  My sql data seek Seek data in the database.  My sql db name Get the name of the database.  My sql db query Send a My SQL query.