More on Functions PHP mod 4 B. Simple Mail Transfer Protocol (SMTP) mail($to, $subject, $msg, $mailheaders); m08/8-1simple_form.html m08/8-1send_simpleform.php.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

Introduction to C Programming
PHP File Upload ISYS 475.
File Management in C. What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
Files in C Rohit Khokher. Files in C Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two.
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.
PHP and the Web: Session : 4. Predefined variables PHP provides a large number of predefined global variables to any script which it runs also called.
1 PHP Storing and Retrieving Data. string fgets(resource handle [, int length]) Reads and returns one line from a file; moves file pointer to next line.
More on PHP Coding Lab no. 6 Advance Database Management System.
PHP Workshop ‹#› File Handling with PHP. PHP Workshop ‹#› Files and PHP File Handling –Data Storage Though slower than a database –Manipulating uploaded.
IS 1181 IS 118 Introduction to Development Tools Week 2.
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.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)Slide Topic Files.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
PHP Basics 2 ICS213, 1 / 2011 Dr. Seung Hwan Kang 1.
ITM 352 © Port,KazmanFile I/O - 1 File I/O in PHP Persistent Data.
Web Programming 02 – PHP File and Directory Handling Aryo Pinandito, ST, M.MT.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Simple Mail Transfer Protocol (SMTP)
BBK P1 Module2010/11 : [‹#›] File Handling with PHP.
18. PHP File Operations Opening a File
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Website Development with PHP and MySQL Saving Data.
Oracle Data Integrator Procedures, Advanced Workflows.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
14. Uploading Files to MySQL Database. M. Udin Harun Al Rasyid, S.Kom, Ph.D Desain dan.
File IO and command line input CSE 2451 Rong Shi.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
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
Introduction to File Processing with PHP - Part 2 Indexed Files.
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.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
PHP 4 Files, Functions. Opening a File The fopen() function is used to open files in PHP. The first parameter of this function contains the name of the.
Chapter 5 Working with Files and Directories PHP Programming with MySQL 2 nd Edition.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
Advanced Web 2012 Lecture 6 Sean Costain Files Sean Costain 2012 Php allows for the : Creation Reading Appending Deleting Uploading And Closing.
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.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
PHP-5- Working with Files and Directories. Reading Files PHP’s file manipulation API is extremely flexible: it lets you read files into a string or into.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
Files A collection of related data treated as a unit. Two types Text
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
 2007 Pearson Education, Inc. All rights reserved. 1 C File Processing.
Files. FILE * u In C, we use a FILE * data type to access files. u FILE * is defined in /usr/include/stdio.h u An example: #include int main() { FILE.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
11 C File Processing.
CGS 3066: Web Programming and Design Spring 2016
File Handling with PHP.
TMF1414 Introduction to Programming
DBW - PHP DBW2017.
Objectives In this chapter, you will:
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
CHAPTER 5 WORKING WITH FILES AND DIRECTORIES PHP PROGRAMMING WITH MYSQL 2ND EDITION MODIFIED BY ANITA PHILIPP –SPRING 2012.
14-мавзу. Cookie, сеанс, FTP и технологиялари
<?php require("header.htm"); ?>
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
CSE 333 – Section 3 POSIX I/O Functions.
Fundamental of Programming (C)
CSE 333 – Section 3 POSIX I/O Functions.
PHP-II.
CSc 352 File I/O Saumya Debray Dept. of Computer Science
Professor Jodi Neely-Ritz University of Florida
Presentation transcript:

More on Functions PHP mod 4 B

Simple Mail Transfer Protocol (SMTP) mail($to, $subject, $msg, $mailheaders); m08/8-1simple_form.html m08/8-1send_simpleform.php

File operations $dir = opendir($dir_name); – – Opens up a directory handle to be used in subsequent closedir(), readdir(), and rewinddir() calls.closedir() readdir()rewinddir() readdir($dir); – – Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem. closedir($dir) – – Closes the directory stream indicated by dir_handle. The stream must have previously been opened by opendir().opendir()

Example m09/9-1listfiles.php filetype() – string filetype ( string $filename ) – Returns the type of the given file.

Opening/closing a file fopen — Opens file or URL – – resource fopen ( string $filename, string $mode [, bool $use_include_path = false [, resource $context ]] ) – fopen() binds a named resource, specified by filename, to a stream. fclose()

Modes of fopen() 'r' Open for reading only; place the file pointer at the beginning of the file. 'r+' Open for reading and writing; place the file pointer at the beginning of the file. 'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'w+‘ Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. 'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. 'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. 'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.

Example M09/9-2newfile.php

Since “w+” truncates the length to 0 … file_exists — Checks whether a file or directory exists exists.php exists.php Example: m09/9-3newfile_checkfirst.php To suppress PHP warnings: – precede PHP functions

To write to a file fwrite — Binary-safe file write – Syntax: int fwrite ( resource $handle, string $string [, int $length ] ) – fwrite() writes the contents of string to the file stream pointed to by handle. – Return value: fwrite() returns the number of bytes written, or FALSE on error. Example: m09/9-4writedata.php die(String message) function

To read from a file fread — Binary-safe file read – Syntac: string fread ( resource $handle, int $length ) – fread() reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read EOF (end of file) is reached a packet becomes available (for network streams) 8192 bytes have been read (after opening userspace stream) – Return: Returns the read string or FALSE in case of error. for warnings - difference between text and binary

Examples m09/9-5readdata.php – Wait a minute! Compare textfile.txt and the printout. Any difference? m09/9-5Breaddata.php To deal with the missing line break, use the nl2br() function – nl2br() - newline_to_break function

contents of a file M09/9-6 contents.php

Copy file copy — Copies file bool copy ( string $source, string $dest [, resource $context ] ) m09/9-7copyfile.php

rename() rename — Renames a file or directory bool rename ( string $oldname, string $newname [, resource $context ] ) Attempts to rename oldname to newname. Return Values – Returns TRUE on success or FALSE on failure. Example: m09/9-8renamefile.php

unlink — Deletes a file bool unlink ( string $filename [, resource $context ] ) – Deletes filename. Similar to the Unix C unlink() function. – Return Values: Returns TRUE on success or FALSE on failure.

Uploading a file How to produce an input element with a Browse button in HTML?

To get a Browse button: m10/10-1upload_form.html

Superglobal $_FILES $_FILES – The $_FILES Superglobal represents data available to a PHP script from HTTP POST file uploads. – Using $_FILES is the currently preferred way to handle uploaded files in PHP.

$_FILES [‘userfile’], where userfile is name of input element $_FILES['userfile']['name'] (Specifies the original name of the file being uploaded on the client computer). $_FILES['userfile']['type'] (Specifies the MIME type of the file being uploaded, for instance, "image/jpeg"). $_FILES['userfile']['size'] (Indicates the size in bytes of the file being uploaded). $_FILES['userfile']['tmp_name'] (Indicates the temporary name used by the web server to store the uploaded file). $_FILES['userfile']['error'] (Specifies the error code associated with a specific file upload).

Variables automatically placed in the $_FILES superglobal img1 is name of input element in the original html form $_FILES[img1][tmp_name] - refers to the temporary file on the web server $_FILES[img1][name] - Actual name of the file that was uploaded $_FILES[img1][size] - size of uploaded file in bytes $_FILES[img1][type] - The MIME type of the uploaded file, such as image/jpg

if ($_FILES["img1"] != "") "C:/wamp/www/m10/".$_FILES[img1][name] ) or die("Couldn't copy the file."); } else { die("No input file specified"); } See m10/10-1do_upload.php