LECTURE 4 Files, File open, Read, Write. File Upload - In this lecture we will teach you how to open, read, and close a file on the server. - PHP Open.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

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.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
CS115_ SENEM KUMOVA METIN 1 FILE OPERATIONS.
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.
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.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 06.
CSCI 171 Presentation 12 Files. Working with files File Streams – sequence of data that is connected with a specific file –Text Stream – Made up of lines.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Website Development Tutorial 3. Outline Getting data from the user using forms Sending data from a form to a PHP program Writing the data to a file for.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Web Programming 02 – PHP File and Directory Handling Aryo Pinandito, ST, M.MT.
PHP Advance. Agenda Server side Includes File Handling Cookies Sessions Error/Exception handling Database handling with MySQL sending.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
20/03/01 Sudeshna Sarkar, CSE, IIT Kharagpur1 File Handling in C Lecture 17c 20/3/01.
BBK P1 Module2010/11 : [‹#›] File Handling with PHP.
18. PHP File Operations Opening a File
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
C Programming – Part 6 File Input and Output
PHP Working with Files. Perancangan dan Pemrograman Web: PHP (wcw) Opening a File fopen (path_to_file, file_mode) File Modes File Mode Description ropen.
File IO and command line input CSE 2451 Rong Shi.
Chapter 8 File-Oriented Input and Output. 8.1 INTRODUCTION a file can also be designed to store data. We can easily update files, A data file as input.
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.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
PHP Programming.
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.
Outline if...else...elseif Statements Switch Loops Functions Arrays Forms.
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.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
 2000 Prentice Hall, Inc. All rights reserved Introduction Data files –Can be created, updated, and processed by C programs –Are used for permanent.
Chapter 7 : File Processing1 File-Oriented Input & Output CHAPTER 7.
1 CHAPTER6 CHAPTER 6. Objectives: You’ll learn about;  Introduction  Files and streams  Creating a sequential access file  Reading data from a sequential.
Chapter 7 Files By C. Shing ITEC Dept Radford University.
24-2 Perform File I/O using file pointers FILE * data-type Opening and closing files Character Input and Output String Input and Output Related Chapter:
12 – PHP Contd. Informatics Department Parahyangan Catholic University.
CHAPTER 8 PHP Advanced อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
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.
Programming for the Web Data Structure Writing to a file Dónal Mulligan BSc MA
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
PHP File Handling. Opening a file Fopen(filename,mode) Closing a file Fclose(filename)
Python File Handling. Python language provides numerous built-in functions Some of the functions widely used for standard input and output operations.
By C. Shing ITEC Dept Radford University
Chapter 6 Persistence-Saving and Retrieving Data
CGS 3066: Web Programming and Design Spring 2016
File Input/Output.
Advanced PHP Lecture by Nutthapat Keawrattanapat
File I/O We are used to reading from and writing to the terminal:
<?php require("header.htm"); ?>
File Handling.
File Access (7.5) CSE 2031 Fall January 2019.
File Access (7.5) CSE 2031 Fall February 2019.
Files.
File Handling in C.
Lecture 6: Processing Forms with PHP
CSc 352 File I/O Saumya Debray Dept. of Computer Science
File I/O We are used to reading from and writing to the terminal:
Presentation transcript:

LECTURE 4 Files, File open, Read, Write

File Upload - In this lecture we will teach you how to open, read, and close a file on the server. - PHP Open File – fopen(file,mode) - The fread() and the fclose() functions are used to read and close file. - The first parameter of fopen() contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened.

Example <?php $myfile = fopen("settings.txt", "r") or die("Unable to open file!"); echo fread($myfile,filesize(“settings.txt")); fclose($myfile); ?>

The file may be opened in one of the following modes: ModesDescription rOpen a file for read only. File pointer starts at the beginning of the file wOpen a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file aOpen a file for write only. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist xCreates a new file for write only. Returns FALSE and an error if file already exists r+Open a file for read/write. File pointer starts at the beginning of the file w+Open a file for read/write. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file a+Open a file for read/write. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist x+Creates a new file for read/write. Returns FALSE and an error if file already exists

fgets() and feof() The fgets() function is used to read a single line from a file. The feof() function checks if the "end-of-file" (EOF) has been reached. The feof() function is useful for looping through data of unknown length. "; } fclose($myfile); ?>

RESULT If settings.txt contains: Zhangali Pernebayev Aknur Abubakirova Aziza Kamet Mukhamed Issa The result will be Zhangali Pernebayev Aknur Abubakirova Aziza Kamet Mukhamed Issa

PHP 5 File Create/Write PHP Create File - fopen(“settings.txt”,”w”); If you use fopen() on a file that does not exist, it will create it, given that the file is opened for writing (w) or appending (a).

EXAMPLE <?php $myfile = fopen(“export.txt", "w") or die("Unable to open file!"); $file = “Ruslan Akzholbek\n"; fwrite($myfile, $file); $file = “Zhanel Anarbek\n"; fwrite($myfile, $file); fclose($myfile); ?>

UPLOAD FILES _______________________________________________________________ _______________________________________________________________ $temp = explode(".",$_FILES["avatar"]["name"]); $new_file = $_SESSION['user_id'].'.'.end($temp); move_uploaded_file($_FILES['avatar']['tmp_name'],"images/".$new_file); header("Location:profile.php"); _______________________________________________________________