SlideShare a Scribd company logo
1 of 6
PHP
FILE UPLOAD:
  To upload files from your browser to your hosting, using PHP,
  the first thing we need to do is create an HTML form that
  allows people to choose the file they want to upload.
       <form enctype="multipart/form-data"
       action="upload.php" method="POST">
  Please choose a file:
       <input name="uploaded" type="file" /><br />
       <input type="submit" value="Upload" />
       </form>

  This form sends data to the file "upload.php", which is

  what we will be creating next to actually upload the file.

  The actual file upload is very simple:

       <?php
       $target = "upload/";
       $target = $target . basename( $_FILES['uploaded']
       ['name']) ;
       $ok=1;
       if(move_uploaded_file($_FILES['uploaded']
       ['tmp_name'], $target))
       {
        echo "The file ". basename( $_FILES['uploadedfile']
         ['name']). " has been uploaded";
       }
       else
       {
         echo "Sorry, there was a problem uploading your file.";
       }?>
This very small piece of code will upload files sent to it by

  your HTML form.

  1.The first line $target = "upload/"; is where we assign the

    folder that files will be uploaded to. As you can see in the

     second line, this folder is relative to the upload.php file

  2.We are not using $ok=1; at the moment but we will later in

    the tutorial.

  3.We then move the uploaded file to where it belongs using

    move_uploaded_file (). This places it in the directory we

    specified at the beginning of our script. If this fails the user

    is given an error message, otherwise they are told that the

    file has been uploaded.



SESSION:

    A PHP session variable is used to store information about, or

    change settings for a user session. Session variables hold

    information about one single user, and are available to all

    pages in one application.
Starting a PHP Session:

     Before you can store user information in your PHP session,

     you must first start up the session.

       <?php session_start(); ?>
       <html>
       <body>
       </body>
       </html>

     The code above will register the user's session with the

     server, allow you to start saving user information, and

     assign a UID for that user's session.

Storing a Session Variable:

     The correct way to store and retrieve session variables is to

      use the PHP $_SESSION variable:

        <?php
        session_start();
         // store session data
        $_SESSION['views']=1;
        ?>
        <html>
        <body>
        <?php
        //retrieve session data
        echo "Pageviews=". $_SESSION['views'];
         ?>
        </body>
        </html>
Output:

       Pageviews=1

Destroying a Session:

    If you wish to delete some session data, you can use the

    unset() or the session_destroy() function.

    The unset() function is used to free the specified session
    variable:
        <?php
        unset($_SESSION['views']);
        ?>
    You can also completely destroy the session by calling the
    session_destroy() function:
        <?php
        session_destroy();
         ?>
COOKIES:
     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 a page with a browser, it will
     send the cookie too. With PHP, you can both create and
     retrieve cookie values.
How to Create a Cookie?
     The setcookie() function is used to set a cookie.
        setcookie(name, value, expire, path, domain);
How to Retrieve a Cookie Value?

     The PHP $_COOKIE variable is used to retrieve a cookie

      value. Example

         <?php
         // Print a cookie
         echo $_COOKIE["user"];
         // A way to view all cookies
         print_r($_COOKIE);
         ?>

How to Delete a Cookie?

     When deleting a cookie you should assure that the expiration

     date is in the past. Example

         <?php
         // set the expiration date to one hour ago
         setcookie("user", "", time()-3600);
         ?>



TYPES OF ERRORS

     1.Notices: These are trivial, non-critical errors that PHP

       encounters while executing a script - for example,

       accessing a variable that has not yet been defined. By

       default, such errors are not displayed to the user at all -

       although you can change this default behavior.
2.Warnings: These are more serious errors - for example,

                                attempting to include() a file which does not exist. By

                                default, these errors are displayed to the user, but they do

                                not result in script termination.

                            3.Fatal errors: These are critical errors - for example,

                                instantiating an object of a non-existent class, or calling a

                                non-existent function. These errors cause the immediate

                                termination of the script, and PHP's default behavior is to

                                display them to the user when they take place.

                  PHP error_log() Function

                                   The
                                     error_log() function sends an error to the server
                                error log, a file or a remote destination.
                               This funtion returns TRUE on success, or FALSE on
                                failure.
                                Syntax:
                                    error_log(error,type,destination,headers)
                                    PHP parse_ini_file() Function
                               The parse_ini_file() function parses a configuration (ini)
                               file and returns the settings in it in an array.
                               Syntax:
                                     parse_ini_file(file,process_sections)

More Related Content

What's hot

Flask - Backend com Python - Semcomp 18
Flask - Backend com Python - Semcomp 18Flask - Backend com Python - Semcomp 18
Flask - Backend com Python - Semcomp 18Lar21
 
Sessions and cookies in php
Sessions and cookies in phpSessions and cookies in php
Sessions and cookies in phpPavan b
 
Filling the flask
Filling the flaskFilling the flask
Filling the flaskJason Myers
 
Check username availability with vue.js and PHP
Check username availability with vue.js and PHPCheck username availability with vue.js and PHP
Check username availability with vue.js and PHPYogesh singh
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Parameter Passing & Session Tracking in PHP
Parameter Passing & Session Tracking in PHPParameter Passing & Session Tracking in PHP
Parameter Passing & Session Tracking in PHPamichoksi
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With MysqlHarit Kothari
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in phpherat university
 
Creating a keystroke logger in unix shell scripting
Creating a keystroke logger in unix shell scriptingCreating a keystroke logger in unix shell scripting
Creating a keystroke logger in unix shell scriptingDan Morrill
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaionglslarmenta
 

What's hot (20)

Flask - Backend com Python - Semcomp 18
Flask - Backend com Python - Semcomp 18Flask - Backend com Python - Semcomp 18
Flask - Backend com Python - Semcomp 18
 
Sessions and cookies in php
Sessions and cookies in phpSessions and cookies in php
Sessions and cookies in php
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Phinx talk
Phinx talkPhinx talk
Phinx talk
 
Filling the flask
Filling the flaskFilling the flask
Filling the flask
 
Check username availability with vue.js and PHP
Check username availability with vue.js and PHPCheck username availability with vue.js and PHP
Check username availability with vue.js and PHP
 
kazumich@acmscamp2010spring
kazumich@acmscamp2010springkazumich@acmscamp2010spring
kazumich@acmscamp2010spring
 
extending-php
extending-phpextending-php
extending-php
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
Parameter Passing & Session Tracking in PHP
Parameter Passing & Session Tracking in PHPParameter Passing & Session Tracking in PHP
Parameter Passing & Session Tracking in PHP
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With Mysql
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 
Creating a keystroke logger in unix shell scripting
Creating a keystroke logger in unix shell scriptingCreating a keystroke logger in unix shell scripting
Creating a keystroke logger in unix shell scripting
 
File Upload
File UploadFile Upload
File Upload
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 
File Uploading in PHP
File Uploading in PHPFile Uploading in PHP
File Uploading in PHP
 
backend
backendbackend
backend
 

Viewers also liked

Mengenal al hafizh ibnu hajar al-asqalai (773-852 h
Mengenal al hafizh ibnu hajar al-asqalai (773-852 hMengenal al hafizh ibnu hajar al-asqalai (773-852 h
Mengenal al hafizh ibnu hajar al-asqalai (773-852 hqyud2001
 
Radó Péter: a felsőoktatás átalakítása
Radó Péter: a felsőoktatás átalakításaRadó Péter: a felsőoktatás átalakítása
Radó Péter: a felsőoktatás átalakításapeterradoster
 
Pengantar metodologi tafsir thabari
Pengantar metodologi tafsir thabariPengantar metodologi tafsir thabari
Pengantar metodologi tafsir thabariqyud2001
 
Oktpol café repertórium_2010
Oktpol café repertórium_2010Oktpol café repertórium_2010
Oktpol café repertórium_2010peterradoster
 
Radó Péter: Decentralization and Accountability in Education
Radó Péter: Decentralization and Accountability in EducationRadó Péter: Decentralization and Accountability in Education
Radó Péter: Decentralization and Accountability in Educationpeterradoster
 
Ami várható radó péter
Ami várható radó péterAmi várható radó péter
Ami várható radó péterpeterradoster
 
Employer Presentation Generic
Employer Presentation GenericEmployer Presentation Generic
Employer Presentation GenericAngela_Lee
 
Tadzkirah al sami ibnu jama'ah
Tadzkirah al sami ibnu jama'ahTadzkirah al sami ibnu jama'ah
Tadzkirah al sami ibnu jama'ahqyud2001
 
Help and hope
Help and hopeHelp and hope
Help and hopemwdigital
 
OktpolCafé repertórium
OktpolCafé repertóriumOktpolCafé repertórium
OktpolCafé repertóriumpeterradoster
 
Eskolen konparaketa teknologia berrien erabilera
Eskolen konparaketa teknologia berrien erabileraEskolen konparaketa teknologia berrien erabilera
Eskolen konparaketa teknologia berrien erabileraguest707a94
 
Péter Radó: Financing for Eqity in Education
Péter Radó: Financing for Eqity in EducationPéter Radó: Financing for Eqity in Education
Péter Radó: Financing for Eqity in Educationpeterradoster
 
21 szd oktatás radó péter
21 szd oktatás radó péter21 szd oktatás radó péter
21 szd oktatás radó péterpeterradoster
 
منهج الحافظ ابن حجر في كتابه بلوغ المرام
منهج الحافظ ابن حجر في كتابه بلوغ المراممنهج الحافظ ابن حجر في كتابه بلوغ المرام
منهج الحافظ ابن حجر في كتابه بلوغ المرامqyud2001
 
Nieuwsbrief april [1]
Nieuwsbrief april [1]Nieuwsbrief april [1]
Nieuwsbrief april [1]guestce3cab
 

Viewers also liked (19)

Mengenal al hafizh ibnu hajar al-asqalai (773-852 h
Mengenal al hafizh ibnu hajar al-asqalai (773-852 hMengenal al hafizh ibnu hajar al-asqalai (773-852 h
Mengenal al hafizh ibnu hajar al-asqalai (773-852 h
 
Radó Péter: a felsőoktatás átalakítása
Radó Péter: a felsőoktatás átalakításaRadó Péter: a felsőoktatás átalakítása
Radó Péter: a felsőoktatás átalakítása
 
Meeting room
Meeting roomMeeting room
Meeting room
 
Pengantar metodologi tafsir thabari
Pengantar metodologi tafsir thabariPengantar metodologi tafsir thabari
Pengantar metodologi tafsir thabari
 
Oktpol café repertórium_2010
Oktpol café repertórium_2010Oktpol café repertórium_2010
Oktpol café repertórium_2010
 
Radó Péter: Decentralization and Accountability in Education
Radó Péter: Decentralization and Accountability in EducationRadó Péter: Decentralization and Accountability in Education
Radó Péter: Decentralization and Accountability in Education
 
An effective and efficient nigerian police force using
An effective and efficient nigerian police force usingAn effective and efficient nigerian police force using
An effective and efficient nigerian police force using
 
Ami várható radó péter
Ami várható radó péterAmi várható radó péter
Ami várható radó péter
 
Employer Presentation Generic
Employer Presentation GenericEmployer Presentation Generic
Employer Presentation Generic
 
Tadzkirah al sami ibnu jama'ah
Tadzkirah al sami ibnu jama'ahTadzkirah al sami ibnu jama'ah
Tadzkirah al sami ibnu jama'ah
 
Help and hope
Help and hopeHelp and hope
Help and hope
 
OktpolCafé repertórium
OktpolCafé repertóriumOktpolCafé repertórium
OktpolCafé repertórium
 
A támop tervezése
A támop tervezéseA támop tervezése
A támop tervezése
 
Eskolen konparaketa teknologia berrien erabilera
Eskolen konparaketa teknologia berrien erabileraEskolen konparaketa teknologia berrien erabilera
Eskolen konparaketa teknologia berrien erabilera
 
Péter Radó: Financing for Eqity in Education
Péter Radó: Financing for Eqity in EducationPéter Radó: Financing for Eqity in Education
Péter Radó: Financing for Eqity in Education
 
21 szd oktatás radó péter
21 szd oktatás radó péter21 szd oktatás radó péter
21 szd oktatás radó péter
 
Apc
ApcApc
Apc
 
منهج الحافظ ابن حجر في كتابه بلوغ المرام
منهج الحافظ ابن حجر في كتابه بلوغ المراممنهج الحافظ ابن حجر في كتابه بلوغ المرام
منهج الحافظ ابن حجر في كتابه بلوغ المرام
 
Nieuwsbrief april [1]
Nieuwsbrief april [1]Nieuwsbrief april [1]
Nieuwsbrief april [1]
 

Similar to Php

Php interview-questions and answers
Php interview-questions and answersPhp interview-questions and answers
Php interview-questions and answerssheibansari
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questionssekar c
 
PHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptxPHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptxShitalGhotekar
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erickokelloerick
 
Tips
TipsTips
Tipsmclee
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questionssubash01
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Cakephp's Cache
Cakephp's CacheCakephp's Cache
Cakephp's Cachevl
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptSreejithVP7
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php PresentationAlan Pinstein
 
Drupal 8 meets to symphony
Drupal 8 meets to symphonyDrupal 8 meets to symphony
Drupal 8 meets to symphonyBrahampal Singh
 

Similar to Php (20)

Ph
PhPh
Ph
 
PHP 2
PHP 2PHP 2
PHP 2
 
Php interview-questions and answers
Php interview-questions and answersPhp interview-questions and answers
Php interview-questions and answers
 
Php BASIC
Php BASICPhp BASIC
Php BASIC
 
18.register login
18.register login18.register login
18.register login
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questions
 
PHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptxPHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptx
 
Php session
Php sessionPhp session
Php session
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
Php basics
Php basicsPhp basics
Php basics
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Tips
TipsTips
Tips
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questions
 
Cake php
Cake phpCake php
Cake php
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Cakephp's Cache
Cakephp's CacheCakephp's Cache
Cakephp's Cache
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Unit 1
Unit 1Unit 1
Unit 1
 
Drupal 8 meets to symphony
Drupal 8 meets to symphonyDrupal 8 meets to symphony
Drupal 8 meets to symphony
 

Php

  • 1. PHP FILE UPLOAD: To upload files from your browser to your hosting, using PHP, the first thing we need to do is create an HTML form that allows people to choose the file they want to upload. <form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> This form sends data to the file "upload.php", which is what we will be creating next to actually upload the file. The actual file upload is very simple: <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded'] ['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded'] ['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile'] ['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; }?>
  • 2. This very small piece of code will upload files sent to it by your HTML form. 1.The first line $target = "upload/"; is where we assign the folder that files will be uploaded to. As you can see in the second line, this folder is relative to the upload.php file 2.We are not using $ok=1; at the moment but we will later in the tutorial. 3.We then move the uploaded file to where it belongs using move_uploaded_file (). This places it in the directory we specified at the beginning of our script. If this fails the user is given an error message, otherwise they are told that the file has been uploaded. SESSION: A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
  • 3. Starting a PHP Session: Before you can store user information in your PHP session, you must first start up the session. <?php session_start(); ?> <html> <body> </body> </html> The code above will register the user's session with the server, allow you to start saving user information, and assign a UID for that user's session. Storing a Session Variable: The correct way to store and retrieve session variables is to use the PHP $_SESSION variable: <?php session_start(); // store session data $_SESSION['views']=1; ?> <html> <body> <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html>
  • 4. Output: Pageviews=1 Destroying a Session: If you wish to delete some session data, you can use the unset() or the session_destroy() function. The unset() function is used to free the specified session variable: <?php unset($_SESSION['views']); ?> You can also completely destroy the session by calling the session_destroy() function: <?php session_destroy(); ?> COOKIES: 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 a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values. How to Create a Cookie? The setcookie() function is used to set a cookie. setcookie(name, value, expire, path, domain);
  • 5. How to Retrieve a Cookie Value? The PHP $_COOKIE variable is used to retrieve a cookie value. Example <?php // Print a cookie echo $_COOKIE["user"]; // A way to view all cookies print_r($_COOKIE); ?> How to Delete a Cookie? When deleting a cookie you should assure that the expiration date is in the past. Example <?php // set the expiration date to one hour ago setcookie("user", "", time()-3600); ?> TYPES OF ERRORS 1.Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.
  • 6. 2.Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination. 3.Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place. PHP error_log() Function                                    The error_log() function sends an error to the server error log, a file or a remote destination. This funtion returns TRUE on success, or FALSE on failure. Syntax: error_log(error,type,destination,headers) PHP parse_ini_file() Function The parse_ini_file() function parses a configuration (ini) file and returns the settings in it in an array. Syntax: parse_ini_file(file,process_sections)