Advanced Web 2012 Lecture 6 Sean Costain 2012. Files Sean Costain 2012 Php allows for the : Creation Reading Appending Deleting Uploading And Closing.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

ASENT_IMPORT.PPT Importing Board Data Last revised 08/10/2005.
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.
More on PHP Coding Lab no. 6 Advance Database Management System.
Welcome to Florida International University Online J.O.B.S. Link Applicant Tutorial.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials File Handling.
DT228/3 Web Development multi page applications/ sharing data.
Tutorial 6 Working with Web Forms
Chapter Apache Installation in Linux- Mandrake. Acknowledgment The following information has been obtained directly from
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.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
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.
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.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
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.
LGC Website and Customer On-line Tools LGC RESOURCE 2014.
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.
ITM 352 © Port,KazmanFile I/O - 1 File I/O in PHP Persistent Data.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
Advanced Web 2012 Lecture 4 Sean Costain PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Advanced Web 2012 Lecture 12 Sean Costain Course Summary Sean Costain 2012 To develop skills in web design and authoring  Html 5 / CSS 3 / PHP.
ASENT_IMPORT.PPT Importing Part Lists and Board Data Last revised 10/28/2009.
Discipline, Crime, and Violence August New DCV Application The DCV application and submission process has been revised beginning with the
18. PHP File Operations Opening a File
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
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.
Packaging for Voracity Solutions Control Panel David Turner.
1 Chapter 7 – Object-Oriented Programming and File Handling spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
Storing and Retrieving Data
Outline Overview Opening a file How to create a file ? Closing a File Check End-of-file Reading a File Line by Line Reading a File Character by Character.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
CST336, Spring 2015 Week 8: PHP File Upload. PHP provides specific functions to handle binary data such as uploading a file into the server, storing it.
Files Tutor: You will need ….
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Phase Test 2 You have been provided with a finished application available from the module web site called Phase Test 2 Sample Application. This application.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Internet Advancement Ore-Ida Council Boy Scouts of America.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
HTML Forms.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
1 HTML forms (cont.)
Company LOGO In the Name of Allah,The Most Gracious, The Most Merciful King Khalid University College of Computer and Information System Web pages Development.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
: Information Retrieval อาจารย์ ธีภากรณ์ นฤมาณนลิณี
Text2PTO: Modernizing Patent Application Filing A Proposal for Submitting Text Applications to the USPTO.
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,
FILE I/O: Low-level 1. The Big Picture 2 Low-Level, cont. Some files are mixed format that are not readable by high- level functions such as xlsread()
Accomplish more with macros! Presenter: Joyce Bell Princeton University
PHP File Handling. Opening a file Fopen(filename,mode) Closing a file Fclose(filename)
>> PHP: File Uploads
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
Handling Files In particular, uploading files.
GDSS – Digital Signature
<?php require("header.htm"); ?>
Handling Files In particular, uploading files.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2016 Section DA MW 4:05-5:20
Presentation transcript:

Advanced Web 2012 Lecture 6 Sean Costain 2012

Files Sean Costain 2012 Php allows for the : Creation Reading Appending Deleting Uploading And Closing Of files.

Create / Open a file Sean Costain 2012 Same command Creates or Opens a file. Opens or Creates the file Critical when dealing with files, always, always close the file once you have finished working with it.

fopen tags Sean Costain 2012 As you may have noticed in the last slide, fopen was followed by a ‘w’ there are 6 methods of tagging the fopen command for file manipulation: ‘r’ : File is read only ‘w’ : File is open for writing, if the file exists overwrites all data and prepares to write data at the start of the file. ‘a’ : Appends data to the end of the file, doesn’t damage any of the current content. ‘r+’ : Reads the file and allows data to be written at the start of the file ‘w+’ : Deletes the contents of the file and allows data to be written to it ‘a+’ : Reads the file and allows data to be added to the file, at the end of the file position. This is the part that gets changed

fclose Sean Costain 2012 Technically, we don’t have to close the files, but it is good programming practice to always close them. PHP is smart enough to do it after finishing the execution, but if you program a close, you won’t cause any ‘accidental’ memory issues. Closing the fileProcess

Writing to a file Sean Costain 2012 There are a couple of ways to write to a file, the first is just a straight write, which will decimate any content in a file. The second is to append data to the end of a file, there by, not overwriting any previous data. And finally, there is the Read/Write option, which appends data to the start of the file. First things first, the file must be opened Open for writing, deletes any data Open for writing, appends data to the end of the file Open for writing, writes data to the start of the file

Writing Cont. Sean Costain 2012 Creates the file testFile.txt Simulates user entry Writes the data into the file This creates a blank file and writes data to it.

Writing Cont. Sean Costain 2012 This creates a blank file and writes data to it. The test file looks like this

Writing Cont. Sean Costain 2012 Opens the file testFile.txt Simulates user entry Writes the data into the file This appends data to the end of a pre- existing file.

Writing Cont. Sean Costain 2012 This appends the data to the end of the existing file. The test file looks like this

Writing Cont. Sean Costain 2012 Opens the file testFile.txt Simulates user entry Writes the data into the file This appends data to the start of a pre- existing file.

Writing Cont. Sean Costain 2012 This appends the data to the start of the existing file. The test file looks like this

Reading the File Sean Costain 2012 Reading the file is straight forward, you open it, stream the data into a variable and then echo that data to the screen. There are two methods, fread and fgets. Fread grabs the file and doesn’t perform any processing on it, fgets, on the other hand, recognizes items like the \n for newline. freads fgets

Deleting a file Sean Costain 2012 When deleting a file, you need to ensure that it is closed first. You can have an fclose listed on the file before you run the delete, but if the file isn’t already open you will get a warning message. This message can be hidden by using the code error_reporting(0); Always make sure it is the correct file you delete Delete the file using unlink

Uploading Files Sean Costain 2012 Uploading a file is one part of the process, you need to be able to save it somewhere. The standard process is that any uploaded files get placed into a temporary folder to be deleted later on, so when you do upload a file into the temporary location, it is useful to move it to a more secure location. This other location can be either in a database; think BLOB or as the file itself. Where you can store the data needed to reference it in a database.

Uploading Files Cont. Sean Costain 2012 Self feeding form The enctype attribute of the tag specifies which content-type to use when submitting the form. "multipart/form-data" is used when a form requires binary data, like the contents of a file, to be uploaded The type="file" attribute of the tag specifies that the input should be processed as a file.

Uploading Files Cont. Sean Costain 2012 Moves the file from the temporary location to the one you have set up. The first parameter is the form's input name and the second index can be either "name", "type", "size", "tmp_name" or "error". Like this: $_FILES["file"]["name"] - the name of the uploaded file $_FILES["file"]["type"] - the type of the uploaded file $_FILES["file"]["size"] - the size in bytes of the uploaded file $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server $_FILES["file"]["error"] - the error code resulting from the file upload

Uploading Files Cont. Sean Costain 2012 This is the information you store in the database along with the raw data as a blob type. For your assessment, if you are uploading image files, think of storing it as files with the link data being stored in the database.

Login for Websites Sean Costain 2012 You’ve all seen them, login forms. So what’s the process? Gather the information and then compare it to the data stored in the database

Login Cont. Sean Costain 2012 So once you have confirmed it is real, then what? The easiest way to ensure that a user is logged in and stays logged in, is to use SESSION variables as shown last week. These variables last only as long as the user has the browser open and the user hasn’t reset the session id by destroying the session. A simple IF..THEN on each ‘secure’ page can then check if the session is valid, if it is, then the user can look at the content of the page, otherwise, they can be redirected back to the login page.