SlideShare a Scribd company logo
File Handling with PHP
Files and PHP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Open/Close a File ,[object Object],[object Object],[object Object]
File Open Modes ‘ r’ Open for reading only. Start at beginning of file. ‘ r+’ Open for reading and writing. Start at beginning of file. ‘ w’ Open for writing only. Remove all previous content, if file doesn’t exist, create it. ‘ a’ Open writing, but start at END of current content. ‘ a+’ Open for reading and writing, start at END and create file if necessary.
File Open/Close Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Now what..? ,[object Object],[object Object]
Reading Data ,[object Object],[object Object],[object Object],[object Object],[object Object]
Reading Data ,[object Object],[object Object],[object Object]
Data Reading Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Data Reading Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open the file and assign the resource to $handle $handle =  fopen ( 'people.txt' ,  'r' );
Data Reading Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],While NOT at the end of the file, pointed to by $handle, get and echo the data line by line while (! feof ($handle)) { echo  fgets ($handle,  1024 ); echo  '<br />' ; }
Data Reading Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Close the file fclose ($handle);
File Open shortcuts.. ,[object Object],[object Object],[object Object],[object Object],[object Object]
Writing Data ,[object Object],[object Object],[object Object]
Data Writing Example ,[object Object],[object Object],[object Object]
Data Writing Example ,[object Object],[object Object],[object Object],$handle =  fopen ( 'people.txt' ,  'a' ); Open file to append data (mode 'a')  fwrite ($handle,  “Fred:Male” ); Write new data (with line break after previous data)
Other File Operations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dealing With Directories ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Directory Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Directory Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Open current directory $handle =  opendir ( './' );
Directory Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Whilst readdir() returns a name, loop through directory contents, echoing results while ( false  !== ($file= readdir ($handle))) { echo   &quot;$file<br />&quot; ; }
Directory Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Close the directory stream closedir ($handle);
Other Directory Operations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Review ,[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

What's hot (17)

Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
 
file
filefile
file
 
File handling in c
File handling in c File handling in c
File handling in c
 
05 File Handling Upload Mysql
05 File Handling Upload Mysql05 File Handling Upload Mysql
05 File Handling Upload Mysql
 
File in c
File in cFile in c
File in c
 
File handling-c
File handling-cFile handling-c
File handling-c
 
File handling in 'C'
File handling in 'C'File 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
 
File handling in c
File handling in cFile handling in c
File handling in c
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C programming file handling
C  programming file handlingC  programming file handling
C programming file handling
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
 
File Management in C
File Management in CFile Management in C
File Management in C
 
File in C language
File in C languageFile in C language
File in C language
 
File handling in c
File handling in cFile handling in c
File handling in c
 
File operations in c
File operations in cFile operations in c
File operations in c
 

Similar to php file uploading

Similar to php file uploading (20)

Php i basic chapter 4
Php i basic chapter 4Php i basic chapter 4
Php i basic chapter 4
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
 
File system
File systemFile system
File system
 
Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3Web Development Course: PHP lecture 3
Web Development Course: PHP lecture 3
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
DIWE - File handling with PHP
DIWE - File handling with PHPDIWE - File handling with PHP
DIWE - File handling with PHP
 
java programming
java programmingjava programming
java programming
 
File handling-dutt
File handling-duttFile handling-dutt
File handling-dutt
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPQuick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
 
File handling in c
File  handling in cFile  handling in c
File handling in c
 
Python data file handling
Python data file handlingPython data file handling
Python data file handling
 
Getting groovy (ODP)
Getting groovy (ODP)Getting groovy (ODP)
Getting groovy (ODP)
 
PHP
PHP PHP
PHP
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
Satz1
Satz1Satz1
Satz1
 
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
 
C 檔案輸入與輸出
C 檔案輸入與輸出C 檔案輸入與輸出
C 檔案輸入與輸出
 
DOM and SAX
DOM and SAXDOM and SAX
DOM and SAX
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 

php file uploading

  • 2.
  • 3.
  • 4. File Open Modes ‘ r’ Open for reading only. Start at beginning of file. ‘ r+’ Open for reading and writing. Start at beginning of file. ‘ w’ Open for writing only. Remove all previous content, if file doesn’t exist, create it. ‘ a’ Open writing, but start at END of current content. ‘ a+’ Open for reading and writing, start at END and create file if necessary.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.