Chapter 5 Web Application Development
Chapter 5 Web Application Development
CHAPTER 5:
Web Application Development
Topics covered:-
Hidden Form Fields
Passing Values
Query Strings
File Uploads
HTTP Headers
Learning Outcomes
At the end of this chapter, you should be able to
• Pass values to a PHP script using hidden form fields
• Pass values to a PHP script using query strings
• Write PHP scripts to upload and download files
• Use HTTP Headers for redirecting a browser to a new URL
phphidden.php
<body>
<?php
echo "<h3>I am sure you guess correctly! <br/>
$_REQUEST['people']</h3>";
?>
</body>
page.php?name1=value1
&name2=value2&name3=value3
• Any space in the string would be problematic.
Solution - use the urlencode() function
Eg:
$url = 'page.php?name=' . urlencode(‘John Smith');
<form enctype="multipart/form-data"
action="script.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE"
value="30000" />
File <input type="file" name="upload" />
• Files are uploaded using the “post” method
• An enctype attribute must have a value of “multipart/form-data,” which
instructs the browser to post multiple sections – one for regular form data
and one for the file contents
• MAX_FILE_SIZE must come before the file input.
• The file input field creates a Browse button for the user to navigate to
the appropriate file to upload
example 4\upload_image.php
AMIT 2043 Web Systems and Technologies
Chapter 5 Web Application Development Slide 11
header(header string);
redirect.php
<?php
$redirect = "Location: " . $_REQUEST['button'] . ".html";
echo header($redirect);
?>
AMIT 2043 Web Systems and Technologies
Chapter 5 Web Application Development Slide 13
<?php // show_image.php
$im= stripslashes($_REQUEST[imname]);
$image = "../uploads/$im";
$info = getimagesize($image);
$fs = filesize($image);
following data:
Element Value
0 image’s width in pixels
Chapter5\add_print.php
Chapter5\view_print.php
Chapter5\edit_stock.php Chapter5\delete_stock.php
AMIT 2043 Web Systems and Technologies
Chapter 5 Web Application Development Slide 19
References
• PHP and MySQL by Ullman, L. Peachpit Press
• PHP Programming with MySQL Second Edition
by Gosselin, D., Kokoska, D. & Easterbrooks, R.
Course Technology