SlideShare une entreprise Scribd logo
1  sur  18
Filing System
WHAT IS FILE
• A collection of data or information.
• One that has a name, called the filename.
• Almost all information stored in a computer must be in a file.
 There are many different types of files:
 data files
 text files
 program files
 directory files and so on.
 Different types of files store different types of information. For example, program files store
programs, whereas text files store text.
OR
 A file is an object on a computer that stores data, information, settings, or commands that are
used with a computer program. In a graphical user interface (GUI) such as Microsoft Windows,
files are shown as unique icons that relate to the program that opens the file.
FILE SYSTEM : magic constants
• MAGIC CONSTANTS
• __FILE__ // The full path and filename of the file
• __LINE__ // The current line number of the file.
• __DIR__ // The directory of the file. (only php 5.3)
• PHP FUNCTION
• dirname(__FILE__);
• File_exists(__FILE__);
• File_exists(dirname(__FILE__) )
• File_exists(dirname(__FILE__).”/basic.html”) ? “yes”:”No”
• Is_file() ;
• Is_file(dirname(__FILE__).”/basic.html” ) ? “y”:”n”
• Is_dir();
• Is_file(dirname(__FILE__) ) ? “y”:”n”
UNDERSTANDING FILE PERMISSIONS: windows file
permissions
PHP AND FILE PERMISSIONS
• Octal notation: 764
PHP AND FILE PERMISSIONS
• Chown()
• Chown(‘file_name.php’,’owner_name’) ;
• Chown only works in php is super user
• Making webserver/PHP a super user is a big issue
• Chmod();
• Fileperms();
• Fileperms(‘file_name.php’) // i.e 103306
• Decoct();
• Decoct(fileperms(‘file_name.php’))
• Sprintf()
• Is_readable();
• Is_writable();
ACCESSING FILES
• Php provides some functions for handling files.
• We can create, write , read, append, copy and their permission can
be set/done.
• fopen — Opens file or URL
• fwrite —
• fread —
• filesize — Gets file size
• fgets — Gets line from file pointer
ACCESSING FILES
• ACCESSING FILES
• fopen( filename , mode );
• Note: When writing to a text file, be sure to use the correct line-ending character! Unix
systems use n, Windows systems use rn, and Macintosh systems use r as the line
ending character.
ACCESSING FILES
Mode Purpose
r • Opens the file for reading only.
• Places the file pointer at the beginning of the file.
r+ • Opens the file for reading and writing.
• Places the file pointer at the beginning of the file.
w • Opens the file for writing only.
• Places the file pointer at the beginning of the file.
and truncates the file to zero length. If files does not
exist then it attempts to create a file.
w+ • Opens the file for reading and writing only.
• Places the file pointer at the beginning of the file.
and truncates the file to zero length. If files does not
exist then it attemts to create a file.
a • Opens the file for writing only.
• Places the file pointer at the end of the file.
• If files does not exist then it attemts to create a file.
a+ • Opens the file for reading and writing only.
• Places the file pointer at the end of the file.
• If files does not exist then it attemts to create a file.
x • Create and open for writing only; place the file pointer at the beginning of the file.
• If the file already exists, the fopen() call will fail by returning FALSE If the file does not exist, attempt to create it.
X+ • Create and open for reading & writing only; place the file pointer at the beginning of the file.
• If the file already exists, the fopen() call will fail by returning FALSE If the file does not exist, attempt to create it.
$file = ‘file-name.txt’;
$handle = fopen( $file , ‘w’)
fclose( $handle );
If ( $handle = fopen( $file , ‘w’)){
flose($handle );
}
ACCESSING FILES
$file = ‘file-name.txt’;
If($handle = fopen( $file , ‘w’) ) { overwrite
Fwrite( $file , “abc”);
Fwrite( $file , ‘123’) ;
Fwrite ( $file , ‘abcn123’) ;
}
WRITING TO FILES
• Once a file is opened using fopen() function it can be read with a function
called fread().
• This function requires two arguments:
• The file pointer
• The length of the file expressed in bytes.
• The file's length can be found using the filesize() function which takes the
file name as its argument and returns the size of the file expressed in
bytes.
• So here are the steps required to read a file with PHP.
• Open a file using fopen() function.
• Get the file's length using filesize() function.
• Read the file's content using fread() function.
• Close the file with fclose() function.
READING FILES
if( $handle = fopen( $file , 'r') ){
//$filesize = filesize( $file );
//$contents = fread( $handle ,$filesize );
//echo fgets( $handle);
while(!feof( $handle )){
$contents .= fgets( $handle );
}
}
echo $contents ;
echo nl2br($contents);
READING FILES
$file = ‘filetext.txt’;
If($handle = fopen( $file , ‘w’)){
Fwrite($handle , “123n456n789”);
$pos = ftell ($handle);
Fwrite( $handle , ‘abcdef’);
Rewind($handle );
Fwrite( $handle , ‘xyz’);
Fclose($handle);
// beware, it will overtype!!!
//Note : a and a+ modes will not let you move the pointer
}
MOVING THE FILE POINTER
• File_put_conents : shortcut for fopen / fwrite / fclose
$file = ‘filetest.txt’;
$content = “111n222n333”;
if( $size = file_put_contents( $file , $conent )){
Echo “a file of {$sie} bytes was created ”;
}
WRITING TO FILES
• Close files first
• Cant delete open files
• Must have permission on folder containing the file
Unlink(‘file_name’);
DELETING FILES
• getcwd — Gets the current working directory.
• rmdir — Removes directory.
• mkdir — Makes directory.
• chdir — Change directory.
• rename — Renames a file or directory.
• readdir — Read entry from directory handle.
• opendir — Open directory handle.
• pathinfo — Returns information about a file path.
WORKING WITH DIRECTORIES
• readfile — Reads the contents of a file and returns the number of
bytes read on success
Other PHP File System Functions

Contenu connexe

Tendances (19)

File-Data structure
File-Data structure File-Data structure
File-Data structure
 
R- create a table from a list of files.... before webmining
R- create a table from a list of files.... before webminingR- create a table from a list of files.... before webmining
R- create a table from a list of files.... before webmining
 
Remove Duplicate Files & Manage
Remove Duplicate Files & ManageRemove Duplicate Files & Manage
Remove Duplicate Files & Manage
 
File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C Programming
 
Unix
UnixUnix
Unix
 
File system
File systemFile system
File system
 
Tag
TagTag
Tag
 
File handling-c
File handling-cFile handling-c
File handling-c
 
TDC São Paulo 2016 - Become a jedi with php streams
TDC São Paulo 2016 - Become a jedi with php streamsTDC São Paulo 2016 - Become a jedi with php streams
TDC São Paulo 2016 - Become a jedi with php streams
 
scdevsumit 2016 - Become a jedi with php streams
scdevsumit 2016 - Become a jedi with php streamsscdevsumit 2016 - Become a jedi with php streams
scdevsumit 2016 - Become a jedi with php streams
 
Data file operations in C++ Base
Data file operations in C++ BaseData file operations in C++ Base
Data file operations in C++ Base
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
 
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streamsTDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
 
File in c
File in cFile in c
File in c
 
File Management
File ManagementFile Management
File Management
 
Php i basic chapter 4
Php i basic chapter 4Php i basic chapter 4
Php i basic chapter 4
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
 

En vedette

City of Salina Booklet - After the Fire
City of Salina Booklet -  After the FireCity of Salina Booklet -  After the Fire
City of Salina Booklet - After the FireCity of Salina
 
Multimodal Design for Technical Writing
Multimodal Design for Technical WritingMultimodal Design for Technical Writing
Multimodal Design for Technical WritingSusan Rauch, PhD
 
Perfect papers software
Perfect papers   softwarePerfect papers   software
Perfect papers softwareguest0a1ce99
 
Why Dropbox Rocks
Why Dropbox RocksWhy Dropbox Rocks
Why Dropbox Rocksjunyu
 
Managing Files
Managing FilesManaging Files
Managing Filesnorzaini
 
Files and directories in Linux 6
Files and directories  in Linux 6Files and directories  in Linux 6
Files and directories in Linux 6Meenakshi Paul
 
Mail merge made easy
Mail merge made easyMail merge made easy
Mail merge made easyRoel Palmaers
 
Spreadsheets Concepts and Vocab
Spreadsheets Concepts and VocabSpreadsheets Concepts and Vocab
Spreadsheets Concepts and VocabDanny Ambrosio
 
Display devices and printers
Display devices and printersDisplay devices and printers
Display devices and printersSajith Neyomal
 
Word Processing Introduction
Word Processing IntroductionWord Processing Introduction
Word Processing IntroductionDanny Ambrosio
 
The Power Of Mail Merge!
The Power Of Mail Merge!The Power Of Mail Merge!
The Power Of Mail Merge!Rina Banerjee
 
Microsoft Excel 2016 Basics Course contents
Microsoft Excel 2016 Basics Course contentsMicrosoft Excel 2016 Basics Course contents
Microsoft Excel 2016 Basics Course contentsAnil Kumar
 
drive, one drive, dropbox
drive, one drive, dropboxdrive, one drive, dropbox
drive, one drive, dropboxbrigitheromero
 
What is word processing software
What is word processing softwareWhat is word processing software
What is word processing softwareOmar Jacalne
 
Word Processing Powerpoint
Word Processing PowerpointWord Processing Powerpoint
Word Processing Powerpointthomsonc4000
 

En vedette (20)

City of Salina Booklet - After the Fire
City of Salina Booklet -  After the FireCity of Salina Booklet -  After the Fire
City of Salina Booklet - After the Fire
 
Multimodal Design for Technical Writing
Multimodal Design for Technical WritingMultimodal Design for Technical Writing
Multimodal Design for Technical Writing
 
Perfect papers software
Perfect papers   softwarePerfect papers   software
Perfect papers software
 
Why Dropbox Rocks
Why Dropbox RocksWhy Dropbox Rocks
Why Dropbox Rocks
 
Managing Files
Managing FilesManaging Files
Managing Files
 
Files and directories in Linux 6
Files and directories  in Linux 6Files and directories  in Linux 6
Files and directories in Linux 6
 
Word Processing
Word ProcessingWord Processing
Word Processing
 
Mail merge made easy
Mail merge made easyMail merge made easy
Mail merge made easy
 
Spreadsheets Concepts and Vocab
Spreadsheets Concepts and VocabSpreadsheets Concepts and Vocab
Spreadsheets Concepts and Vocab
 
Display devices and printers
Display devices and printersDisplay devices and printers
Display devices and printers
 
Windows File Systems
Windows File SystemsWindows File Systems
Windows File Systems
 
Word Processing Introduction
Word Processing IntroductionWord Processing Introduction
Word Processing Introduction
 
Parts of letter
Parts of letterParts of letter
Parts of letter
 
The Power Of Mail Merge!
The Power Of Mail Merge!The Power Of Mail Merge!
The Power Of Mail Merge!
 
Microsoft Excel 2016 Basics Course contents
Microsoft Excel 2016 Basics Course contentsMicrosoft Excel 2016 Basics Course contents
Microsoft Excel 2016 Basics Course contents
 
Word version 2016
Word version 2016Word version 2016
Word version 2016
 
drive, one drive, dropbox
drive, one drive, dropboxdrive, one drive, dropbox
drive, one drive, dropbox
 
What is word processing software
What is word processing softwareWhat is word processing software
What is word processing software
 
Word Processing Powerpoint
Word Processing PowerpointWord Processing Powerpoint
Word Processing Powerpoint
 
Maricel olleres how_to_use_dropbox
Maricel olleres how_to_use_dropboxMaricel olleres how_to_use_dropbox
Maricel olleres how_to_use_dropbox
 

Similaire à Filing system in PHP

Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Gheyath M. Othman
 
C-Programming File-handling-C.pptx
C-Programming  File-handling-C.pptxC-Programming  File-handling-C.pptx
C-Programming File-handling-C.pptxLECO9
 
C-Programming File-handling-C.pptx
C-Programming  File-handling-C.pptxC-Programming  File-handling-C.pptx
C-Programming File-handling-C.pptxSKUP1
 
file management in c language
file management in c languagefile management in c language
file management in c languagechintan makwana
 
File Handling Python
File Handling PythonFile Handling Python
File Handling PythonAkhil Kaushik
 
File Handling in C Programming for Beginners
File Handling in C Programming for BeginnersFile Handling in C Programming for Beginners
File Handling in C Programming for BeginnersVSKAMCSPSGCT
 
File handing in C
File handing in CFile handing in C
File handing in Cshrishcg
 
C-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.pptC-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.pptssuserad38541
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.pptyuvrajkeshri
 
File handling With Solve Programs
File handling With Solve ProgramsFile handling With Solve Programs
File handling With Solve ProgramsRohan Gajre
 

Similaire à Filing system in PHP (20)

PHP Filing
PHP Filing PHP Filing
PHP Filing
 
Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3
 
C-Programming File-handling-C.pptx
C-Programming  File-handling-C.pptxC-Programming  File-handling-C.pptx
C-Programming File-handling-C.pptx
 
C-Programming File-handling-C.pptx
C-Programming  File-handling-C.pptxC-Programming  File-handling-C.pptx
C-Programming File-handling-C.pptx
 
Files
FilesFiles
Files
 
Files
FilesFiles
Files
 
file management in c language
file management in c languagefile management in c language
file management in c language
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
File Handling in C Programming for Beginners
File Handling in C Programming for BeginnersFile Handling in C Programming for Beginners
File Handling in C Programming for Beginners
 
File handing in C
File handing in CFile handing in C
File handing in C
 
finally.c.ppt
finally.c.pptfinally.c.ppt
finally.c.ppt
 
C-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.pptC-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.ppt
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
 
637225560972186380.pdf
637225560972186380.pdf637225560972186380.pdf
637225560972186380.pdf
 
DIWE - File handling with PHP
DIWE - File handling with PHPDIWE - File handling with PHP
DIWE - File handling with PHP
 
pspp-rsk.pptx
pspp-rsk.pptxpspp-rsk.pptx
pspp-rsk.pptx
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
File handling With Solve Programs
File handling With Solve ProgramsFile handling With Solve Programs
File handling With Solve Programs
 
File accessing modes in c
File accessing modes in cFile accessing modes in c
File accessing modes in c
 
File Handling in C
File Handling in CFile Handling in C
File Handling in C
 

Plus de Mudasir Syed

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php Mudasir Syed
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2Mudasir Syed
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1Mudasir Syed
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDFMudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2Mudasir Syed
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1 Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminMudasir Syed
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joinsMudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir Syed
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagramMudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatinMudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functionsMudasir Syed
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions Mudasir Syed
 

Plus de Mudasir Syed (20)

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1
 
Ajax
Ajax Ajax
Ajax
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
 
Sql select
Sql select Sql select
Sql select
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql Sql
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions
 

Dernier

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Dernier (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

Filing system in PHP

  • 2. WHAT IS FILE • A collection of data or information. • One that has a name, called the filename. • Almost all information stored in a computer must be in a file.  There are many different types of files:  data files  text files  program files  directory files and so on.  Different types of files store different types of information. For example, program files store programs, whereas text files store text. OR  A file is an object on a computer that stores data, information, settings, or commands that are used with a computer program. In a graphical user interface (GUI) such as Microsoft Windows, files are shown as unique icons that relate to the program that opens the file.
  • 3. FILE SYSTEM : magic constants • MAGIC CONSTANTS • __FILE__ // The full path and filename of the file • __LINE__ // The current line number of the file. • __DIR__ // The directory of the file. (only php 5.3) • PHP FUNCTION • dirname(__FILE__); • File_exists(__FILE__); • File_exists(dirname(__FILE__) ) • File_exists(dirname(__FILE__).”/basic.html”) ? “yes”:”No” • Is_file() ; • Is_file(dirname(__FILE__).”/basic.html” ) ? “y”:”n” • Is_dir(); • Is_file(dirname(__FILE__) ) ? “y”:”n”
  • 4. UNDERSTANDING FILE PERMISSIONS: windows file permissions
  • 5. PHP AND FILE PERMISSIONS • Octal notation: 764
  • 6. PHP AND FILE PERMISSIONS • Chown() • Chown(‘file_name.php’,’owner_name’) ; • Chown only works in php is super user • Making webserver/PHP a super user is a big issue • Chmod(); • Fileperms(); • Fileperms(‘file_name.php’) // i.e 103306 • Decoct(); • Decoct(fileperms(‘file_name.php’)) • Sprintf() • Is_readable(); • Is_writable();
  • 7. ACCESSING FILES • Php provides some functions for handling files. • We can create, write , read, append, copy and their permission can be set/done. • fopen — Opens file or URL • fwrite — • fread — • filesize — Gets file size • fgets — Gets line from file pointer
  • 8. ACCESSING FILES • ACCESSING FILES • fopen( filename , mode ); • Note: When writing to a text file, be sure to use the correct line-ending character! Unix systems use n, Windows systems use rn, and Macintosh systems use r as the line ending character.
  • 9. ACCESSING FILES Mode Purpose r • Opens the file for reading only. • Places the file pointer at the beginning of the file. r+ • Opens the file for reading and writing. • Places the file pointer at the beginning of the file. w • Opens the file for writing only. • Places the file pointer at the beginning of the file. and truncates the file to zero length. If files does not exist then it attempts to create a file. w+ • Opens the file for reading and writing only. • Places the file pointer at the beginning of the file. and truncates the file to zero length. If files does not exist then it attemts to create a file. a • Opens the file for writing only. • Places the file pointer at the end of the file. • If files does not exist then it attemts to create a file. a+ • Opens the file for reading and writing only. • Places the file pointer at the end of the file. • If files does not exist then it attemts to create a file. x • Create and open for writing only; place the file pointer at the beginning of the file. • If the file already exists, the fopen() call will fail by returning FALSE If the file does not exist, attempt to create it. X+ • Create and open for reading & writing only; place the file pointer at the beginning of the file. • If the file already exists, the fopen() call will fail by returning FALSE If the file does not exist, attempt to create it.
  • 10. $file = ‘file-name.txt’; $handle = fopen( $file , ‘w’) fclose( $handle ); If ( $handle = fopen( $file , ‘w’)){ flose($handle ); } ACCESSING FILES
  • 11. $file = ‘file-name.txt’; If($handle = fopen( $file , ‘w’) ) { overwrite Fwrite( $file , “abc”); Fwrite( $file , ‘123’) ; Fwrite ( $file , ‘abcn123’) ; } WRITING TO FILES
  • 12. • Once a file is opened using fopen() function it can be read with a function called fread(). • This function requires two arguments: • The file pointer • The length of the file expressed in bytes. • The file's length can be found using the filesize() function which takes the file name as its argument and returns the size of the file expressed in bytes. • So here are the steps required to read a file with PHP. • Open a file using fopen() function. • Get the file's length using filesize() function. • Read the file's content using fread() function. • Close the file with fclose() function. READING FILES
  • 13. if( $handle = fopen( $file , 'r') ){ //$filesize = filesize( $file ); //$contents = fread( $handle ,$filesize ); //echo fgets( $handle); while(!feof( $handle )){ $contents .= fgets( $handle ); } } echo $contents ; echo nl2br($contents); READING FILES
  • 14. $file = ‘filetext.txt’; If($handle = fopen( $file , ‘w’)){ Fwrite($handle , “123n456n789”); $pos = ftell ($handle); Fwrite( $handle , ‘abcdef’); Rewind($handle ); Fwrite( $handle , ‘xyz’); Fclose($handle); // beware, it will overtype!!! //Note : a and a+ modes will not let you move the pointer } MOVING THE FILE POINTER
  • 15. • File_put_conents : shortcut for fopen / fwrite / fclose $file = ‘filetest.txt’; $content = “111n222n333”; if( $size = file_put_contents( $file , $conent )){ Echo “a file of {$sie} bytes was created ”; } WRITING TO FILES
  • 16. • Close files first • Cant delete open files • Must have permission on folder containing the file Unlink(‘file_name’); DELETING FILES
  • 17. • getcwd — Gets the current working directory. • rmdir — Removes directory. • mkdir — Makes directory. • chdir — Change directory. • rename — Renames a file or directory. • readdir — Read entry from directory handle. • opendir — Open directory handle. • pathinfo — Returns information about a file path. WORKING WITH DIRECTORIES
  • 18. • readfile — Reads the contents of a file and returns the number of bytes read on success Other PHP File System Functions