This document discusses PHP file handling functions. It covers opening, reading, writing, and closing files. Specific functions covered include fopen(), fread(), fwrite(), fclose(), touch(), unlink(), file_exists(), filesize(), include(), and require(). Examples are provided for creating, opening, reading from, writing to, and closing files. File inclusion is also discussed as a way to include the contents of one PHP file into another before execution.
php complete reference with database concepts for beginners is generally useful for those who want to start the career as a php developer. given each and every information right from the scratch to understand for the beginners and students as well. I hope this will help you a lot for the beginners to start the career.
php complete reference with database concepts for beginners is generally useful for those who want to start the career as a php developer. given each and every information right from the scratch to understand for the beginners and students as well. I hope this will help you a lot for the beginners to start the career.
We are covering following topics:
If...Else...Elseif Statements: if statement executes some code if one condition is true.
Switch Statement: Switch Statement tests a variable against a series of values.
For Loop: For loop executes a block of code a specified number of times.
While Loop: While loop executes a block of code as long as the specified condition is true.
Do…While Loop: Do...While loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.
PHP stands for “PHP: Hypertext Preprocessor”. It is very good for creating dynamic content. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.
Esoft Metro Campus - Diploma in Web Engineering - (Module VIII) Multimedia Technologies
(Template - Virtusa Corporate)
Contents:
include and require Statements
include and require
include_once Statement
Validating Files
file_exists() function
is_dir() function
is_readable() function
is_writable() function
is_executable() function
filesize() function
filemtime() function
filectime() function
fileatime() function
Creating and deleting files
touch() function
unlink() function
File reading, writing and appending
Open File - fopen()
Close File - fclose()
Read File - fread()
Read Single Line - fgets()
Check End-Of-File - feof()
Read Single Character - fgetc()
Seek File - fseek()
Write File - fwrite()
Write File - fputs()
Lock File - flock()
Working with Directories
Create directory - mkdir()
Remove directory - rmdir()
Open directory - opendir()
Read directory - readdir()
We are covering following topics:
If...Else...Elseif Statements: if statement executes some code if one condition is true.
Switch Statement: Switch Statement tests a variable against a series of values.
For Loop: For loop executes a block of code a specified number of times.
While Loop: While loop executes a block of code as long as the specified condition is true.
Do…While Loop: Do...While loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.
PHP stands for “PHP: Hypertext Preprocessor”. It is very good for creating dynamic content. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.
Esoft Metro Campus - Diploma in Web Engineering - (Module VIII) Multimedia Technologies
(Template - Virtusa Corporate)
Contents:
include and require Statements
include and require
include_once Statement
Validating Files
file_exists() function
is_dir() function
is_readable() function
is_writable() function
is_executable() function
filesize() function
filemtime() function
filectime() function
fileatime() function
Creating and deleting files
touch() function
unlink() function
File reading, writing and appending
Open File - fopen()
Close File - fclose()
Read File - fread()
Read Single Line - fgets()
Check End-Of-File - feof()
Read Single Character - fgetc()
Seek File - fseek()
Write File - fwrite()
Write File - fputs()
Lock File - flock()
Working with Directories
Create directory - mkdir()
Remove directory - rmdir()
Open directory - opendir()
Read directory - readdir()
Brief PPT on File Handling Operations which includes opening, closing, writing, reading of the file. The program done in this is worked on DEV C++. but i advice the viewers and the students who wants to take the idea then please do practice your and your own program as an example so that you will understand the topic very well.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
2. Contents
• Files and Directories
• Write to Files
• Read from Files
• Create Directories
• Upload Files
• Rename and Delete Files and Directories
6/17/2023 2
3. PHP File Handling
• File handling is an important part of any web
application.
• You often need to open and process a file for
different tasks.
• PHP has several functions for creating, reading,
and editing files.
• The files can be .doc file, .txt file, .xml file any
kind of file supports all php function for
manipulate files.
6/17/2023 3
4. PHP File Open and Read
• how to open file , read file and close file using
file handling functions:
1. fopen() – open file
2. fread() – read file
3. fclose() – close file
6/17/2023 4
5. PHP Create File - fopen()
• The fopen() function is used to create a file..
• If you use fopen() on a file that does not exist, it
will create it.
• The example below creates a new file called
"testfile.txt".
• The file will be created in the same directory
where the PHP code resides:
$myfile = fopen("testfile.txt", "w");
6/17/2023 5
6. File functions The use of functions
touch() used to create a file.
unlink() used to delete a file.
copy() used to copy a file.
rename() used to rename a file.
file_exists() used to check whether the file exists or not.
filesize() used to check size of file.
realpath() used to check real path of file.
fopen() used to open existing file.
fread() used to reads from an pen file.
fwrite() used to write to file.
fclose() used to close an open file.
fgets() used to read a single line from a file.
fgetc() used to read a single character from a file.
feof() used to check ‘end of file’.
6/17/2023 6
7. PHP fopen() function
• PHP fopen() function used to open a file. If file
does not exist then fopen() function will create
a new file.
• The fopen() function must use with mode
character like ‘w’, ‘a’ ,’r’ etc.
<?php
fopen(“filename with extension”, “mode char”);
?>
6/17/2023 7
9. Example - fopen()
<?php
//open text file
fopen("abc.txt","w");
//open ms word .doc file
fopen("abc.doc","w");
//open pdf file
fopen('abc.pdf',"w");
?>
6/17/2023 9
10. PHP Read File - fread()
• The fread() function reads from an open file.
• The first parameter of fread() contains the
name of the file to read from and the second
parameter specifies the maximum number of
bytes to read.
• fread($myfile,filesize("webdictionary.txt"));
6/17/2023 10
11. Example
• <!DOCTYPE html>
<html>
<body>
<?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable
to open file!");
echo fread($myfile,filesize("webdictionary.txt"));
fclose($myfile);
?>
</body>
</html>
6/17/2023 11
12. PHP close file – fclose()
• The fclose() function is used to close an open
file.
• PHP fclose() syntax
<?php
fclose(“filename”);
?>
6/17/2023 12
13. PHP File Create and Write
• how to create a file and how to write to a file
on the server.
• Create a File – touch() ,
• Create a File, if does not exist – fopen()
• Write to a File – fwrite()
6/17/2023 13
14. touch() and fopen()
<?php
//create text file
touch("abc.txt");
//create ms word .doc
file
touch("abc.doc");
//create pdf file
touch('abc.pdf');
?>
<?php
//create text file
fopen("abc.txt","w");
//create word .doc file
fopen("abc.doc","w");
//create pdf file
fopen('abc.pdf',"w");
?>
6/17/2023 14
15. PHP Write to File - fwrite()
• The fwrite() function is used to write to a file.
• The first parameter of fwrite() contains the
name of the file to write to and the second
parameter is the string to be written.
• The example below writes a couple of names
into a new file called "newfile.txt":
6/17/2023 15
16. <?php
$myfile = fopen("newfile.txt", "w") or die("Unable
to open file!");
$txt = "John Doen";
fwrite($myfile, $txt);
$txt = "Jane Doen";
fwrite($myfile, $txt);
fclose($myfile);
?>
6/17/2023 16
20. PHP Close File - fclose()
• The fclose() function is used to close an open
file.
• It's a good programming practice to close all
files after you have finished with them.
• The fclose() requires the name of the file (or a
variable that holds the filename) we want to
close:
6/17/2023 20
22. PHP Check End-Of-File - feof()
• The feof() function checks if the "end-of-file" (EOF)
has been reached.
• The example below reads the "webdictionary.txt" file
line by line, until end-of-file is reached:
<?php
$file = fopen("abc.txt", "r");
while(! feof($file)) {
echo fgets($file). "<br>";
}
fclose($file);
?>
6/17/2023 22
23. PHP Read Single Character - fgetc()
• The fgetc() function is used to read a single
character from a file.
<?php
$myfile =
fopen("webdictionary.txt", "r") or die("Unable to
open file!");
// Output one character until end-of-file
while(!feof($myfile)) {
echo fgetc($myfile);
}
fclose($myfile);
?>
6/17/2023 23
24. PHP copy() Function
• The copy() function copies a file.
• Note: If the to_file file already exists, it will be
overwritten.
• Syntax
copy(from_file, to_file, context)
<?php
Echo copy("webdictionary.doc","studMark.doc");
?>
6/17/2023 24
26. PHP file_exists() Function
• The file_exists() function checks whether a file
or directory exists.
Syntax
file_exists(path)
• Check whether a file exists:
<?php
echo file_exists(“stud1.txt");
?>
6/17/2023 26
27. filesize() Function
• The filesize() function returns the size of a file.
• Return the file size for "test.txt":
<?php
echo filesize("test.txt");
?>
6/17/2023 27
28. PHP File Inclusion
• PHP has two function which can used to
include one PHP file into another PHP file
before the server executes it.
1. The include() function
2. The require() function
• For the designing purpose in web forms the
same header, footer or menu displayed on all
web pages of website.
6/17/2023 28
29. • Programmer has to design same menu on
multiple pages, if changes required in future it
will very complicated to open all pages then make
change on all pages.
• for resolving this problem we use include and
require function in php.
• Just design menu or header in one php page and
display same menu on multiple pages using
include function.
• if changes required on menu.php page, it will
make effect on all other pages automatically.
6/17/2023 29
30. The include() function
• The include function copy all text of one PHP
file into another PHP file that used the include
statement.
• The include function used when we use same
menu or header on multiple pages of a
website.
• PHP include() syntax:
include ‘ filename’;
6/17/2023 30
32. Example2
<?php
echo '<a href="/default.asp">Home</a> -
<a href="/html/default.asp">HTML
Tutorial</a> -
<a href="/css/default.asp">CSS Tutorial</a> -
<a href="/js/default.asp">JavaScript
Tutorial</a> -
<a href="default.asp">PHP Tutorial</a>';
?>
<html>
<body>
<div class="menu">
<?php include 'menu.php';?>
</div>
<h1>Welcome to my home
page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
</body>
</html>
Assume we have a standard menu file called
"menu.php":
6/17/2023 32
33. Example3
<?php
$color='red';
$car='BMW';
?>
<html>
<body>
<h1>Welcome to my home page!</h1>
<?php include 'vars.php';
echo "I have a $color $car.";
?>
</body>
</html>
Assume we have a file called
"vars.php", with some variables
defined:
Then, if we include the "vars.php" file, the
variables can be used in the calling file:
6/17/2023 33
34. PHP include Example
• We have a same header for all website pages so
create “header.php” file like:
<?php
echo "<h1> Welcomme
Meera Academy
</h1>";
?>
<html>
<body>
<?php include 'header.php'; ?>
<p>The first page of site</p>
</body>
</html>
6/17/2023 34
37. The PHP require() Function
• The require() function copy all the text from one
php file into another php file that uses the
require() function.
• In require() function there is a problem with file
then the require() function generate fatal error
and stop execution of code.
• while the include() function will continue to
execute script.
• The require() function is better than the include()
function, because scripts not to be continue if file
has problem or missing.
6/17/2023 37