Uploading Files. Why? By giving a user the option to upload a file you are creating an interactive page You can enable users have a greater web experience.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

PHP File Upload ISYS 475.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
CIS101 Introduction to Computing Week 08. Agenda Your questions JavaScript text Resume project HTML Project Six This week online Next class.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Video, audio, embed, iframe, HTML Form
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
Tutorial 6 Working with Web Forms
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
Python and Web Programming
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
FILE UPLOADS CHAPTER 11. THE BASIC PROCESS 1.The HTML form displays the control to locate and upload a file 2.Upon form submission, the server first stores.
File uploading in PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
U NIT 4 F ILE U PLOAD. I. C REATE AN U PLOAD -F ILE F ORM - With PHP, it is possible to upload files to the server.To allow users to upload files from.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
ITM © Port, Kazman1 ITM 352 HTML Forms, Basic Form Processing.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Server-side Scripting Powering the webs favourite services.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
A little PHP. Enter the simple HTML code seen below.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 HTML Forms
ITCS373: Internet Technology Lecture 5: More HTML.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
Creating PHPs to Insert, Update, and Delete Data CS 320.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
1 HTML Forms
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
HTLM Forms CS3505. Form Handling in Browser html User Files out form WEbBROWSErWEbBROWSEr User read response submit Get URL?input html Get file html script.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
1 HTML forms (cont.)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Creating Web Page Forms COE 201- Computer Proficiency.
HTML Forms.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
1 HTML forms (cont.)
CSE 154 LECTURE 18: FORMS AND UPLOADING FILES. Exercise: Baby name web service JSON Modify our babynames.php service to produce its output as JSON. For.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
Unit 7 How to Upload Files. A very useful aspect of PHP is its ability to manage file uploads to your server. Before you can use PHP to manage your uploads,
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Web Engineering Lecture-08.
A little PHP.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Section 17.1 Section 17.2 Add an audio file using HTML
Passing variables between pages
PHP-II.
Presentation transcript:

Uploading Files

Why? By giving a user the option to upload a file you are creating an interactive page You can enable users have a greater web experience through these interactions You will enable the user to have greater control over the webpage.

Introduction You will need two pages to create this function A html page with a form A php page with server side scripting (php and mySql)

HTML page

The most important part of this page is This page will allow the user to search for their image.

PHP page

What’s important with this page is The underlying code

The connection HTML page The user can browse for their image/file they wish to upload. When they have found the file they are to upload the file through a button. PHP page This page will contain the server side code which will process the upload function. This will upload the file into a specified folder (images folder) In this example this page also allows the user to enter data associated to the file. Submit

The form Please search for your employee's photograph before inserting other details

Dissecting the code : Opening form tag enctype=“multipart/form-data”: Specifies the type of data stored in the form action=“path/filename”: the file the form will go to next after form is submitted method=“post”: The location in which the data is encoded. ( How the data is being sent)

: A form input area. Allows user to enter data. type=“file”: This specifies the type of data being entered. For this example it is a file. name=“uploadFile”: The name of the form input. There can be many form inputs by giving each one a specific name you can target a particular input of data. Id=“uploadFile”: Class identification, for design purposes.

type=“submit”: A submit button name=“action”: The name of this particular form input value=“Upload file”: The text that appears on the submit button The closing form tag, indicates the end of the form.

Method: Get vs Post Get method will encode the data of a form within the URL. The data sent has to be for simple retrieval purposes. Post method will encode the data of a form within the body of a page. The post method can be used for complex form interactions such as uploading and storing files, sending an and etc

The PHP code <?php $target_path = "images/"; $target_path = $target_path. basename( $_FILES['uploadFile']['name']); if(move_uploaded_file($_FILES['uploadFile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadFile']['name']). " has been uploaded"; } else { echo "There was an error uploading the file, please try again!"; } ?>

PHP code dissected <?php: The opening php tag. PHP code always needs to be within an opening and closing php tag. $target_path = "images/"; A variable called $target_path. This variable will contain the images folder pathway

$target_path = $target_path. basename( $_FILES['uploadFile']['name']); Starget_path=$target_path: The same variable will equal itself in order to automatically update the contents information..basename: base name to a file. $_FILES: creates an array containing the file name of the uploaded file Note: Arrays “allow the programmer to store more than one value in a variable, whilst retaining a single reference.” [uploadFile’]: associated index from the form file input type. (The name of the form element on the HTML page) [‘name’]: associated index from the original file name. This name will reflect the original file name as stored on the local computer. (The name of the original file that is being uploaded)

if(move_uploaded_file($_FILES['uploadFile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadFile']['name']). " has been uploaded"; } else { echo "There was an error uploading the file, please try again!"; } ?> If statement: If the function move_uploaded_file; of array with (form element name) and temporary name to the folder path (images), has been completed then display “The file (filename) has been uploaded.” Otherwise Display “There was an error uploading the file, please try again!” End of if statement Closing of php tag

If statements If statements provide conditions that your webpage must meet in order to execute a particular function.