SlideShare a Scribd company logo
Introduction to PHP
Web programming
Week 11, day2
Web programming
PHP with HTML
• You can embed PHP code inside html:
<html>
<body>
<h1>
<?php
$str_one = "Helloo World!";
echo $str_one;
?>
</h1>
</body>
</html>
• Or you can call html from php:
<?php
echo "<html><body><h2>Helloo Baabtra</h2></body></html>”;
?>
Client - Server communication with Form Data
When you submit the form- all form element data(username and password ) will
be send to the file ‚registration.php‛ which is residing on your server
HTML Form Example
HTML Form Example
Action specifies where to send the form data? Normally we
specify a page which resides on server so that all form data will be
sent to that page. In this example when you click submit button
data you entered will be send to “registation.php”
HTML Form Example
We can send data to server in two ways
GET or POST.
Form action and methods
•There are two methods that we can send form data from client to server
• GET
• Allows you to send data as part of the query string.That means data will
be appended with the url
•http://example.org/index.php?list=user&orderby=name&direction=asc
• POST
Allows the client to send along a data payload, for example, if you are
posting an HTTP form, the payload could consist of the form data, while if
you are uploading a file, the payload would consist of the file itself. Payload
will be with HTTP request so that it will not be visible to the user
Comparison
• Data sent will be shown in the URL
• Size of Data can be send is limiter
normally ~2kb but its browser
dependant
• Cannot be used to send binary
data like image or document
• Bookmarking is possible with GET
method
• Data will not be shown with the browser
• No restrictions on size of data
• Can be used to send files
• Book marking is not possible with POST
method
GET POST
How will you get that data in ‚registration.php‛ ???
• All the form data sent via Get method will be stored in a super global Array
$_GET
• Eg: http://example.org/index.php?list=user&orderby=name&direction=asc
echo $_GET*’list’+;
• You can create arrays by using array notation...
Eg: http://example.org/index.php?list=user&order[by]=column&order[dir]=asc
•and then access them using the following syntax:
echo $_GET*’order’+*’by’+;
echo $_GET*’order’+*’direction’+;
How will you get that data in ‚registration.php‛ ???
• Similarly all the form data sent via POST method will be stored in a super global
array $_POST
•Eg:
echo $_POST*‘name’+; // will output baabtra
echo $_POST*‘email’+; // will output info@baabtra.com
When You Don’t Know How Data Is Sent
• If you want to receive data send by client browser but you don’t know the method
they used to send (GET or POST), you can do this by using $_REQUEST[] super
global array
• ie. $_REQUEST[] will contain what ever data you send in any method either GET
or POST.
• Eg: echo $_REQUEST*‘name’+;
Try this
• Create a HTML form as below . Try both Get and POST methods
• Up on clicking submit button it should display what user have
entered
localhost/test/Registration.php
Baabtra
info@baabtra.com
localhost/test/Registration.php
Managing File uploads
File Uploading
• File uploads are an important feature for many Web applications;
• A file can be uploaded through a ‚multi-part‛ HTTP POST
transaction.
<form enctype="multipart/form-data" action="index.php‚ method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
File Uploading
• File uploads are an important feature for many Web applications;
• A file can be uploaded through a ‚multi-part‛ HTTP POST
transaction.
<form enctype="multipart/form-data" action="index.php‚ method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
is an encoding type that allows files to be sent
through a POST. Quite simply, without this
encoding the files cannot be sent through POST.
File Uploading
• File uploads are an important feature for many Web applications;
• A file can be uploaded through a ‚multi-part‛ HTTP POST
transaction.
<form enctype="multipart/form-data" action="index.php‚ method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
MAX_FILE_SIZE value is used to define the
maximum file size allowed
(in this case, 50,000 bytes)
File Uploading
• File uploads are an important feature for many Web applications;
• A file can be uploaded through a ‚multi-part‛ HTTP POST
transaction.
<form enctype="multipart/form-data" action="index.php‚ method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
Tip :You can limit the amount of data uploaded by a POST operation
by modifying number of configuration directives in php.ini, such as
post_max_size, max_input_time and upload_max_filesize.
How will you receive the file at server side?
• Once a file is uploaded to the server, PHP stores it in a temporary location and
makes it available to the script; It is up to the script to move the file to a safe
location. The temporary copy is automatically destroyed when the script ends.
• Inside your script, uploaded files will appear in the $_FILES super global multi
dimensional array. This array will have the following keys
– name : The original name of the file
– type : The MIME type of the file provided by the browser
– size : The size (in bytes) of the file
– tmp_name : The name of the file’s temporary location
– error : The error code associated with this file. A value of
UPLOAD_ERR_OK indicates a successful transfer
Built in functions for file upload()
• is_uploaded_file(filename) : returns true if the file has uploaded to the
temporary location in server
• Accepts and argument ‚filename‛ which refers to the name of the file in servers
temporary position.ie it will be $_FILE*‘filename’+*‘tmp_name’+
• move_uploaded_file(source,destination) : to move an uploaded file to a
different location
• Source refers to its current location which obviously is in the temporary
location in the server ie $_FILE*‘filename’+*‘tmp_name’+
• Destination refers to where to move the file along with its name eg.
‚images/profilePics/‛. $_FILE*‘filename’+*‘name’+
form enctype="multipart/form-data" action=‚register.php‚ method="post">
<input type="file" name="filedata" />
<input type="submit" value="Send file" />
</form>
Example – File Upload
Index.html
<?php
echo $_FILE*‘filedata’+*‘name’+; // prints the name of file uploaded
echo $_FILE*‘filedata’+*‘size’+; // prints the size of file uploaded
is_uploaded_file($_FILE*‘filedata’+*‘tmp_name’+)
{
$target=‚images/‛.$_FILE*‘filedata’+*‘name’+;
move_upload_file($_FILE*‘filedata’+*‘tmp_name’+,$target);
}
?>
Example – File Upload
Register.php
Questions?
‚A good question deserve a good grade…‛
End of day
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

What's hot (20)

PPT
Applet life cycle
myrajendra
 
PPTX
Php functions
JIGAR MAKHIJA
 
PPTX
Multi-Dimensional Lists
primeteacher32
 
PDF
Java conditional statements
Kuppusamy P
 
PPTX
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
 
PPTX
PHP Functions & Arrays
Henry Osborne
 
PPT
Java Threads
M Vishnuvardhan Reddy
 
PPSX
Algorithm and Programming (Sorting)
Adam Mukharil Bachtiar
 
PPTX
Evaluation of postfix expression
Akhil Ahuja
 
PPT
08 Dynamic SQL and Metadata
rehaniltifat
 
PPTX
Array in c
Harsh Bhanushali
 
PPTX
Java loops for, while and do...while
Jayfee Ramos
 
PPT
Switch statements in Java
Jin Castor
 
PPTX
Tree Traversal
Md. Israil Fakir
 
PPTX
String function in my sql
knowledgemart
 
PDF
Prolog,Prolog Programming IN AI.pdf
CS With Logic
 
PPTX
Access modifiers in java
Madishetty Prathibha
 
PPTX
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
Applet life cycle
myrajendra
 
Php functions
JIGAR MAKHIJA
 
Multi-Dimensional Lists
primeteacher32
 
Java conditional statements
Kuppusamy P
 
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
 
PHP Functions & Arrays
Henry Osborne
 
Java Threads
M Vishnuvardhan Reddy
 
Algorithm and Programming (Sorting)
Adam Mukharil Bachtiar
 
Evaluation of postfix expression
Akhil Ahuja
 
08 Dynamic SQL and Metadata
rehaniltifat
 
Array in c
Harsh Bhanushali
 
Java loops for, while and do...while
Jayfee Ramos
 
Switch statements in Java
Jin Castor
 
Tree Traversal
Md. Israil Fakir
 
String function in my sql
knowledgemart
 
Prolog,Prolog Programming IN AI.pdf
CS With Logic
 
Access modifiers in java
Madishetty Prathibha
 
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 

Viewers also liked (20)

PDF
Introduction to php web programming - sessions and cookies
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Class 6 - PHP Web Programming
Ahmed Swilam
 
PPT
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
PDF
Introduction to PHP
Bradley Holt
 
PDF
Php & mysql course syllabus
Papitha Velumani
 
PPT
Php Presentation
Manish Bothra
 
PPTX
Php project training in ahmedabad
Developers Academy
 
PDF
Html , php, mysql intro
Nagarajan Kamalakannan
 
PPT
Php essentials
sagaroceanic11
 
PDF
PHP Project development with Vagrant
Bahattin Çiniç
 
PDF
開始網站設計
James Shieh
 
PDF
PHP an intro -1
Kanchilug
 
PDF
MySQL資料庫設計規劃與phpMyAdmin
James Shieh
 
PDF
Intro to Web Design
Cassie McDaniel
 
PDF
Php course-syllabus
Himanshu Himanshu
 
PDF
AI Chatbot Service Framework based on Backpropagation Network for Predicting ...
James Shieh
 
PPT
GTU PHP Project Training Guidelines
TOPS Technologies
 
PPT
Intro to Web Design
Kathy Gill
 
PPTX
Scripting languages
Diane Phillips Krebs
 
PPTX
Introduction to xampp
Jin Castor
 
Introduction to php web programming - sessions and cookies
baabtra.com - No. 1 supplier of quality freshers
 
Class 6 - PHP Web Programming
Ahmed Swilam
 
Introduction to PHP
Bradley Holt
 
Php & mysql course syllabus
Papitha Velumani
 
Php Presentation
Manish Bothra
 
Php project training in ahmedabad
Developers Academy
 
Html , php, mysql intro
Nagarajan Kamalakannan
 
Php essentials
sagaroceanic11
 
PHP Project development with Vagrant
Bahattin Çiniç
 
開始網站設計
James Shieh
 
PHP an intro -1
Kanchilug
 
MySQL資料庫設計規劃與phpMyAdmin
James Shieh
 
Intro to Web Design
Cassie McDaniel
 
Php course-syllabus
Himanshu Himanshu
 
AI Chatbot Service Framework based on Backpropagation Network for Predicting ...
James Shieh
 
GTU PHP Project Training Guidelines
TOPS Technologies
 
Intro to Web Design
Kathy Gill
 
Scripting languages
Diane Phillips Krebs
 
Introduction to xampp
Jin Castor
 
Ad

Similar to Introduction to php web programming - get and post (20)

PPTX
PHP fundamnetal in information technology CHapter -02.pptx
worldchannel
 
PDF
GET and POST in PHP
Vineet Kumar Saini
 
PPTX
Web Techniques like Cookies and Sessions
SonaliAbhang
 
PPTX
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
PPTX
Web application, cookies and sessions
hamsa nandhini
 
PDF
Web Development Course: PHP lecture 2
Gheyath M. Othman
 
PPTX
Chapter 6 Getting Data from the Client (1).pptx
AhmedKafi7
 
PPTX
lecture 11.pptx
ITNet
 
DOCX
Copy of cgi
Abhishek Kesharwani
 
PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
PDF
PHP-Part4
Ahmed Saihood
 
PPT
05 File Handling Upload Mysql
Geshan Manandhar
 
PPT
Lecture7 form processing by okello erick
okelloerick
 
PDF
Web app development_php_07
Hassen Poreya
 
PPTX
forms.pptx
asmabagersh
 
KEY
Creating forms
Ray Villalobos
 
DOCX
Php advance
Rattanjeet Singh
 
PDF
Web Development Course: PHP lecture 4
Gheyath M. Othman
 
PPTX
Uploading a file with php
Muhamad Al Imran
 
PHP fundamnetal in information technology CHapter -02.pptx
worldchannel
 
GET and POST in PHP
Vineet Kumar Saini
 
Web Techniques like Cookies and Sessions
SonaliAbhang
 
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
Web application, cookies and sessions
hamsa nandhini
 
Web Development Course: PHP lecture 2
Gheyath M. Othman
 
Chapter 6 Getting Data from the Client (1).pptx
AhmedKafi7
 
lecture 11.pptx
ITNet
 
Copy of cgi
Abhishek Kesharwani
 
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
PHP-Part4
Ahmed Saihood
 
05 File Handling Upload Mysql
Geshan Manandhar
 
Lecture7 form processing by okello erick
okelloerick
 
Web app development_php_07
Hassen Poreya
 
forms.pptx
asmabagersh
 
Creating forms
Ray Villalobos
 
Php advance
Rattanjeet Singh
 
Web Development Course: PHP lecture 4
Gheyath M. Othman
 
Uploading a file with php
Muhamad Al Imran
 
Ad

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
PDF
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 

Recently uploaded (20)

PPTX
Manual Testing for Accessibility Enhancement
Julia Undeutsch
 
PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pdf
ghjghvhjgc
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
Edge AI and Vision Alliance
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
[GDGoC FPTU] Spring 2025 Summary Slidess
minhtrietgect
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
PDF
Survival Models: Proper Scoring Rule and Stochastic Optimization with Competi...
Paris Women in Machine Learning and Data Science
 
PPTX
Essential Content-centric Plugins for your Website
Laura Byrne
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Home Cleaning App Development Services.pdf
V3cube
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Manual Testing for Accessibility Enhancement
Julia Undeutsch
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pdf
ghjghvhjgc
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
Edge AI and Vision Alliance
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
[GDGoC FPTU] Spring 2025 Summary Slidess
minhtrietgect
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
Survival Models: Proper Scoring Rule and Stochastic Optimization with Competi...
Paris Women in Machine Learning and Data Science
 
Essential Content-centric Plugins for your Website
Laura Byrne
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Home Cleaning App Development Services.pdf
V3cube
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 

Introduction to php web programming - get and post

  • 1. Introduction to PHP Web programming Week 11, day2
  • 3. PHP with HTML • You can embed PHP code inside html: <html> <body> <h1> <?php $str_one = "Helloo World!"; echo $str_one; ?> </h1> </body> </html> • Or you can call html from php: <?php echo "<html><body><h2>Helloo Baabtra</h2></body></html>”; ?>
  • 4. Client - Server communication with Form Data
  • 5. When you submit the form- all form element data(username and password ) will be send to the file ‚registration.php‛ which is residing on your server HTML Form Example
  • 6. HTML Form Example Action specifies where to send the form data? Normally we specify a page which resides on server so that all form data will be sent to that page. In this example when you click submit button data you entered will be send to “registation.php”
  • 7. HTML Form Example We can send data to server in two ways GET or POST.
  • 8. Form action and methods •There are two methods that we can send form data from client to server • GET • Allows you to send data as part of the query string.That means data will be appended with the url •http://example.org/index.php?list=user&orderby=name&direction=asc • POST Allows the client to send along a data payload, for example, if you are posting an HTTP form, the payload could consist of the form data, while if you are uploading a file, the payload would consist of the file itself. Payload will be with HTTP request so that it will not be visible to the user
  • 9. Comparison • Data sent will be shown in the URL • Size of Data can be send is limiter normally ~2kb but its browser dependant • Cannot be used to send binary data like image or document • Bookmarking is possible with GET method • Data will not be shown with the browser • No restrictions on size of data • Can be used to send files • Book marking is not possible with POST method GET POST
  • 10. How will you get that data in ‚registration.php‛ ??? • All the form data sent via Get method will be stored in a super global Array $_GET • Eg: http://example.org/index.php?list=user&orderby=name&direction=asc echo $_GET*’list’+; • You can create arrays by using array notation... Eg: http://example.org/index.php?list=user&order[by]=column&order[dir]=asc •and then access them using the following syntax: echo $_GET*’order’+*’by’+; echo $_GET*’order’+*’direction’+;
  • 11. How will you get that data in ‚registration.php‛ ??? • Similarly all the form data sent via POST method will be stored in a super global array $_POST •Eg: echo $_POST*‘name’+; // will output baabtra echo $_POST*‘email’+; // will output [email protected]
  • 12. When You Don’t Know How Data Is Sent • If you want to receive data send by client browser but you don’t know the method they used to send (GET or POST), you can do this by using $_REQUEST[] super global array • ie. $_REQUEST[] will contain what ever data you send in any method either GET or POST. • Eg: echo $_REQUEST*‘name’+;
  • 13. Try this • Create a HTML form as below . Try both Get and POST methods • Up on clicking submit button it should display what user have entered localhost/test/Registration.php Baabtra [email protected] localhost/test/Registration.php
  • 15. File Uploading • File uploads are an important feature for many Web applications; • A file can be uploaded through a ‚multi-part‛ HTTP POST transaction. <form enctype="multipart/form-data" action="index.php‚ method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form>
  • 16. File Uploading • File uploads are an important feature for many Web applications; • A file can be uploaded through a ‚multi-part‛ HTTP POST transaction. <form enctype="multipart/form-data" action="index.php‚ method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form> is an encoding type that allows files to be sent through a POST. Quite simply, without this encoding the files cannot be sent through POST.
  • 17. File Uploading • File uploads are an important feature for many Web applications; • A file can be uploaded through a ‚multi-part‛ HTTP POST transaction. <form enctype="multipart/form-data" action="index.php‚ method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form> MAX_FILE_SIZE value is used to define the maximum file size allowed (in this case, 50,000 bytes)
  • 18. File Uploading • File uploads are an important feature for many Web applications; • A file can be uploaded through a ‚multi-part‛ HTTP POST transaction. <form enctype="multipart/form-data" action="index.php‚ method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form> Tip :You can limit the amount of data uploaded by a POST operation by modifying number of configuration directives in php.ini, such as post_max_size, max_input_time and upload_max_filesize.
  • 19. How will you receive the file at server side? • Once a file is uploaded to the server, PHP stores it in a temporary location and makes it available to the script; It is up to the script to move the file to a safe location. The temporary copy is automatically destroyed when the script ends. • Inside your script, uploaded files will appear in the $_FILES super global multi dimensional array. This array will have the following keys – name : The original name of the file – type : The MIME type of the file provided by the browser – size : The size (in bytes) of the file – tmp_name : The name of the file’s temporary location – error : The error code associated with this file. A value of UPLOAD_ERR_OK indicates a successful transfer
  • 20. Built in functions for file upload() • is_uploaded_file(filename) : returns true if the file has uploaded to the temporary location in server • Accepts and argument ‚filename‛ which refers to the name of the file in servers temporary position.ie it will be $_FILE*‘filename’+*‘tmp_name’+ • move_uploaded_file(source,destination) : to move an uploaded file to a different location • Source refers to its current location which obviously is in the temporary location in the server ie $_FILE*‘filename’+*‘tmp_name’+ • Destination refers to where to move the file along with its name eg. ‚images/profilePics/‛. $_FILE*‘filename’+*‘name’+
  • 21. form enctype="multipart/form-data" action=‚register.php‚ method="post"> <input type="file" name="filedata" /> <input type="submit" value="Send file" /> </form> Example – File Upload Index.html
  • 22. <?php echo $_FILE*‘filedata’+*‘name’+; // prints the name of file uploaded echo $_FILE*‘filedata’+*‘size’+; // prints the size of file uploaded is_uploaded_file($_FILE*‘filedata’+*‘tmp_name’+) { $target=‚images/‛.$_FILE*‘filedata’+*‘name’+; move_upload_file($_FILE*‘filedata’+*‘tmp_name’+,$target); } ?> Example – File Upload Register.php
  • 23. Questions? ‚A good question deserve a good grade…‛
  • 25. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: [email protected]