SlideShare uma empresa Scribd logo
1 de 22
Internet
programming-1
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 1
Chap 5 files & directories
What we learn?
Random access to file data
Getting information on file
Ownership and permissions
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 2
Random access to file data
1.Ftell()
Tells current position of file pointer
$pos=ftell($fp);
2.Rewind()
To set fp at beginning
Rewind($fp);
3.Fseek()
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 3
Fseek($fp,offset,[position])
To set fp to perticulat position in file
Ex. Fseek($fp,100,SEEK_CUR);
$data=fread($fp,10);
echo $s;
3 positions-
1. SEEK_SET(1)-bydefault / beginning to offset
2. SEEK_CUR(0)-from current position to offset
3. SEEK_END(2)-from end position to offset
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 4
Getting information about file
•Files contain much information about themselves, such as their size,
when they were modified, who owns them, and so forth.
•PHP includes the stat() function to enable you to capture information
about a file by providing the filename as an argument to the function.
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 5
Gettting information of file
stat() function contains
0 Dev Device number
1 Ino Inode number
2 Mode Inode protection mode
3 nlink Number of links
4 uid Userid of owner
5 gid Group id of owner
6 rdev Device type, if inode device
7 size Size in bytes
8 atime Time of last access
9 mtime Time of last modification
10 ctime Time of last change
11 blksize Blocksize of file system
12 blocks Number of blocks allocated
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 7
To get size of file-f.php
<?php
$arr=stat("abc.txt");
echo $arr[7];
echo $arr['size'];
$size=filesize("abc.txt");
echo $size;
?>
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 8
$arr=stat(“a.txt”);
echo $arr[‘atime’];
•$file_stats = stat(“data.txt");
•$file_size = $file_stats[7];
•Functions-
1. $s=Filesize(“a.txt”);
2. $o=fileowner(“a.txt”);
3. $t=Filetype(“a.txt”);
4. $t=filectime(“a.txt”);
5. $t=fileatime(“a.txt”);
6. $t=filemtime(“a.txt”);
Ownership and permissions
1)posix_getpwuid() returns information of uid.
$arr=posix_getpwuid(int uid)
Information can be –
Name Password
Uid Gid
Dir shell
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 9
2)posix_getgrgid()
returns array of information of group
$arr=posix_getpwuid(int gid)
Information can be –
Name Password
Gid Members
<?php
$groupid = posix_getegid();
$groupinfo = posix_getgrgid($groupid);
print_r($groupinfo);
?>
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 10
Flock()
flock(file, lock, block)
By allowing so many users at a time to script files may corrupt so for
locking flock() used.
flock($file,LOCK_UN);
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 11
Fileowner()
Filegroup()
Filetype()
Is_dir()
Is_file()
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 12
Working with directories
Steps-
1) Open dir
2) read / update dir
3) close dir
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 13
Opendir()
opendir(path, context)
Dir handler returned
$dh=opendir(dirname);
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
//operations
}
closedir($dh);
}
}
?> MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 14
Readdir()
readdir(dir handeler)
Returns contents file/ sub directories
<?php
$dir="./img/";
if (is_dir($dir))
{
If($dh=opendir($dir)){
while(($file=readdir($dh))!=false)
{
echo $file;
} }
}
else
echo "no dir";}
?>
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 15
Closedir()
closedir(dir)
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
//operations
}
closedir($dh);
}
}
?>
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 16
4) Rewinddir($dh)
5) chdir(dir name)
6) rmdir(dir name)
7) mkdir( path)
8) dirname(path) returns object of directory //same as base name()
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 17
9)dir()
<?php
$d = dir(getcwd());
//or
$d = dir( “var/www/html” );
echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";
while (($file = $d->read()) !== false){
echo "filename: " . $file . "<br>";
}
$d->close();
?>
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 18
Server side includes(SSI)
1)require()
2) require_once()
3)include()
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 19
Difference between require() & include()
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 20
Require() Include()
1 Require(“a,txt”); Include(“a.txt”);
2 Use require() only when file required May require or not
3 Generate error E_COMPILE_ERROR if
file not found
If no file found no error,gives
E_WARNING
4 & stop execution if error & just continue execution though error
Show files with specific extenstion
f.html
<html>
<body>
<form method=get action=“f.php">
enter file extenstion<input type=text name="txt"><br>
<input type=submit value="show file">
</form>
</body>
</html>
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 21
f.php
<?php
$ext=$_GET['txt'];
$dh=opendir(".");
while($f=readdir($dh))
{
$arr=explode('.',$f);
if(strcmp($arr[1],$ext)==0)
echo $f;
}
?>
MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 22

Mais conteúdo relacionado

Mais procurados

Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal coredrumm
 
Hadoop installation
Hadoop installationHadoop installation
Hadoop installationhabeebulla g
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Noé Fernández-Pozo
 
One Page Linux Manual
One Page Linux ManualOne Page Linux Manual
One Page Linux Manualdummy
 
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 streamsMatheus Marabesi
 
HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係Kiwamu Okabe
 
Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012rivierarb
 
Lecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erickLecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erickokelloerick
 
Mkscript sh
Mkscript shMkscript sh
Mkscript shBen Pope
 
Being Google
Being GoogleBeing Google
Being GoogleTom Dyson
 
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 streamsMatheus Marabesi
 
Meta Buscadores
Meta BuscadoresMeta Buscadores
Meta Buscadorespechever
 
Web Application Security 101 - 05 Enumeration
Web Application Security 101 - 05 EnumerationWeb Application Security 101 - 05 Enumeration
Web Application Security 101 - 05 EnumerationWebsecurify
 
Introducing FSter
Introducing FSterIntroducing FSter
Introducing FSteritsmesrl
 
자바스터디 4
자바스터디 4자바스터디 4
자바스터디 4jangpd007
 
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntuMengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntuAlferizhy Chalter
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Pythonpugpe
 

Mais procurados (20)

Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal core
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 
Hadoop installation
Hadoop installationHadoop installation
Hadoop installation
 
Rhel1
Rhel1Rhel1
Rhel1
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014
 
Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
 
One Page Linux Manual
One Page Linux ManualOne Page Linux Manual
One Page Linux Manual
 
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
 
HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係
 
Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012Pry at the Ruby Drink-up of Sophia, February 2012
Pry at the Ruby Drink-up of Sophia, February 2012
 
Lecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erickLecture5 my sql statements by okello erick
Lecture5 my sql statements by okello erick
 
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
 
Being Google
Being GoogleBeing Google
Being Google
 
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
 
Meta Buscadores
Meta BuscadoresMeta Buscadores
Meta Buscadores
 
Web Application Security 101 - 05 Enumeration
Web Application Security 101 - 05 EnumerationWeb Application Security 101 - 05 Enumeration
Web Application Security 101 - 05 Enumeration
 
Introducing FSter
Introducing FSterIntroducing FSter
Introducing FSter
 
자바스터디 4
자바스터디 4자바스터디 4
자바스터디 4
 
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntuMengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 

Semelhante a Chap 5 php files part-2

Chap 5 php files part 1
Chap 5 php files part 1Chap 5 php files part 1
Chap 5 php files part 1monikadeshmane
 
Filesystem abstractions and msg queue sergeev - symfony camp 2018
Filesystem abstractions and msg queue   sergeev - symfony camp 2018Filesystem abstractions and msg queue   sergeev - symfony camp 2018
Filesystem abstractions and msg queue sergeev - symfony camp 2018Юлия Коваленко
 
PHP CLI: A Cinderella Story
PHP CLI: A Cinderella StoryPHP CLI: A Cinderella Story
PHP CLI: A Cinderella StoryMike Lively
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHPNicole Ryan
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model Perforce
 
Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Ahmed El-Arabawy
 
Hadoop & HDFS for Beginners
Hadoop & HDFS for BeginnersHadoop & HDFS for Beginners
Hadoop & HDFS for BeginnersRahul Jain
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous phpWim Godden
 
Linux_Ch2 Lecture (1).pdf
Linux_Ch2 Lecture (1).pdfLinux_Ch2 Lecture (1).pdf
Linux_Ch2 Lecture (1).pdfAllinOne746595
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
File handling-c programming language
File handling-c programming languageFile handling-c programming language
File handling-c programming languagethirumalaikumar3
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Martijn Verburg
 
Path::Tiny
Path::TinyPath::Tiny
Path::Tinywaniji
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file managementAcácio Oliveira
 

Semelhante a Chap 5 php files part-2 (20)

Chap 5 php files part 1
Chap 5 php files part 1Chap 5 php files part 1
Chap 5 php files part 1
 
Filesystem abstractions and msg queue sergeev - symfony camp 2018
Filesystem abstractions and msg queue   sergeev - symfony camp 2018Filesystem abstractions and msg queue   sergeev - symfony camp 2018
Filesystem abstractions and msg queue sergeev - symfony camp 2018
 
Unit5
Unit5Unit5
Unit5
 
Oops in php
Oops in phpOops in php
Oops in php
 
PHP CLI: A Cinderella Story
PHP CLI: A Cinderella StoryPHP CLI: A Cinderella Story
PHP CLI: A Cinderella Story
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHP
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model
 
Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands Course 102: Lecture 3: Basic Concepts And Commands
Course 102: Lecture 3: Basic Concepts And Commands
 
File system
File systemFile system
File system
 
Perl Programming - 03 Programming File
Perl Programming - 03 Programming FilePerl Programming - 03 Programming File
Perl Programming - 03 Programming File
 
Hadoop & HDFS for Beginners
Hadoop & HDFS for BeginnersHadoop & HDFS for Beginners
Hadoop & HDFS for Beginners
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
Linux_Ch2 Lecture (1).pdf
Linux_Ch2 Lecture (1).pdfLinux_Ch2 Lecture (1).pdf
Linux_Ch2 Lecture (1).pdf
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
File handling-c programming language
File handling-c programming languageFile handling-c programming language
File handling-c programming language
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2
 
File in C language
File in C languageFile in C language
File in C language
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Path::Tiny
Path::TinyPath::Tiny
Path::Tiny
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file management
 

Mais de monikadeshmane

Mais de monikadeshmane (20)

File system node js
File system node jsFile system node js
File system node js
 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
 
Nodejs buffers
Nodejs buffersNodejs buffers
Nodejs buffers
 
Intsllation & 1st program nodejs
Intsllation & 1st program nodejsIntsllation & 1st program nodejs
Intsllation & 1st program nodejs
 
Nodejs basics
Nodejs basicsNodejs basics
Nodejs basics
 
Chap4 oop class (php) part 2
Chap4 oop class (php) part 2Chap4 oop class (php) part 2
Chap4 oop class (php) part 2
 
Chap4 oop class (php) part 1
Chap4 oop class (php) part 1Chap4 oop class (php) part 1
Chap4 oop class (php) part 1
 
Chap 3php array part4
Chap 3php array part4Chap 3php array part4
Chap 3php array part4
 
Chap 3php array part 3
Chap 3php array part 3Chap 3php array part 3
Chap 3php array part 3
 
Chap 3php array part 2
Chap 3php array part 2Chap 3php array part 2
Chap 3php array part 2
 
Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
 
PHP function
PHP functionPHP function
PHP function
 
php string part 4
php string part 4php string part 4
php string part 4
 
php string part 3
php string part 3php string part 3
php string part 3
 
php string-part 2
php string-part 2php string-part 2
php string-part 2
 
PHP string-part 1
PHP string-part 1PHP string-part 1
PHP string-part 1
 
java script
java scriptjava script
java script
 
ip1clientserver model
 ip1clientserver model ip1clientserver model
ip1clientserver model
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
 
Chap1introppt1php basic
Chap1introppt1php basicChap1introppt1php basic
Chap1introppt1php basic
 

Último

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
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
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
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
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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"
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
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
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

Chap 5 php files part-2

  • 2. What we learn? Random access to file data Getting information on file Ownership and permissions MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 2
  • 3. Random access to file data 1.Ftell() Tells current position of file pointer $pos=ftell($fp); 2.Rewind() To set fp at beginning Rewind($fp); 3.Fseek() MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 3
  • 4. Fseek($fp,offset,[position]) To set fp to perticulat position in file Ex. Fseek($fp,100,SEEK_CUR); $data=fread($fp,10); echo $s; 3 positions- 1. SEEK_SET(1)-bydefault / beginning to offset 2. SEEK_CUR(0)-from current position to offset 3. SEEK_END(2)-from end position to offset MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 4
  • 5. Getting information about file •Files contain much information about themselves, such as their size, when they were modified, who owns them, and so forth. •PHP includes the stat() function to enable you to capture information about a file by providing the filename as an argument to the function. MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 5
  • 6. Gettting information of file stat() function contains 0 Dev Device number 1 Ino Inode number 2 Mode Inode protection mode 3 nlink Number of links 4 uid Userid of owner 5 gid Group id of owner 6 rdev Device type, if inode device 7 size Size in bytes 8 atime Time of last access 9 mtime Time of last modification 10 ctime Time of last change 11 blksize Blocksize of file system 12 blocks Number of blocks allocated
  • 7. MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 7 To get size of file-f.php <?php $arr=stat("abc.txt"); echo $arr[7]; echo $arr['size']; $size=filesize("abc.txt"); echo $size; ?>
  • 8. MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 8 $arr=stat(“a.txt”); echo $arr[‘atime’]; •$file_stats = stat(“data.txt"); •$file_size = $file_stats[7]; •Functions- 1. $s=Filesize(“a.txt”); 2. $o=fileowner(“a.txt”); 3. $t=Filetype(“a.txt”); 4. $t=filectime(“a.txt”); 5. $t=fileatime(“a.txt”); 6. $t=filemtime(“a.txt”);
  • 9. Ownership and permissions 1)posix_getpwuid() returns information of uid. $arr=posix_getpwuid(int uid) Information can be – Name Password Uid Gid Dir shell MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 9
  • 10. 2)posix_getgrgid() returns array of information of group $arr=posix_getpwuid(int gid) Information can be – Name Password Gid Members <?php $groupid = posix_getegid(); $groupinfo = posix_getgrgid($groupid); print_r($groupinfo); ?> MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 10
  • 11. Flock() flock(file, lock, block) By allowing so many users at a time to script files may corrupt so for locking flock() used. flock($file,LOCK_UN); MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 11
  • 13. Working with directories Steps- 1) Open dir 2) read / update dir 3) close dir MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 13
  • 14. Opendir() opendir(path, context) Dir handler returned $dh=opendir(dirname); <?php $dir = "/images/"; // Open a directory, and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ //operations } closedir($dh); } } ?> MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 14
  • 15. Readdir() readdir(dir handeler) Returns contents file/ sub directories <?php $dir="./img/"; if (is_dir($dir)) { If($dh=opendir($dir)){ while(($file=readdir($dh))!=false) { echo $file; } } } else echo "no dir";} ?> MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 15
  • 16. Closedir() closedir(dir) <?php $dir = "/images/"; // Open a directory, and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ //operations } closedir($dh); } } ?> MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 16
  • 17. 4) Rewinddir($dh) 5) chdir(dir name) 6) rmdir(dir name) 7) mkdir( path) 8) dirname(path) returns object of directory //same as base name() MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 17
  • 18. 9)dir() <?php $d = dir(getcwd()); //or $d = dir( “var/www/html” ); echo "Handle: " . $d->handle . "<br>"; echo "Path: " . $d->path . "<br>"; while (($file = $d->read()) !== false){ echo "filename: " . $file . "<br>"; } $d->close(); ?> MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 18
  • 19. Server side includes(SSI) 1)require() 2) require_once() 3)include() MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 19
  • 20. Difference between require() & include() MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 20 Require() Include() 1 Require(“a,txt”); Include(“a.txt”); 2 Use require() only when file required May require or not 3 Generate error E_COMPILE_ERROR if file not found If no file found no error,gives E_WARNING 4 & stop execution if error & just continue execution though error
  • 21. Show files with specific extenstion f.html <html> <body> <form method=get action=“f.php"> enter file extenstion<input type=text name="txt"><br> <input type=submit value="show file"> </form> </body> </html> MONICA DESHMANE(H.V.DESAI COLLEGE,PUNE) 21