PHP File Handling(file system)

The file system functions allow you to access and manipulate the file.

file system provides a concept to start a specific data using different types of file format.

That means file gives us linear type database concept. There is no any type of relations will be found with value because it doesn’t support RDBMS concept.

Through this concept you will retrieved data from disk files, XML documents and many other data sources.

Files In a computer, a file system (sometimes written filesystem) is the way in which files are named and where they are placed logically for storage and retrieval.

The DOS, Windows, OS/2, Macintosh, and UNIX-based operating systems all have file systems in which files are placed somewhere in a hierarchical (tree) structure.

A file is placed in a directory (folder in Windows) or sub-directory at the desired place in the tree structure.

How to Create a file using PHP

touch( ) function is used to create a file

Syntax

Eg

Output
Check your folder manually
(same folder where you have saved your program) a file will be created


How to Delete a file using PHP

unlink( ) function is used to delete a file

Syntax

Eg

Output
Check your folder manually
(same folder where you have saved your program) a file will be deleted


How to copy a file using PHP

copy( ) function is used to copy file
Syntax

Eg

Output
Check your folder manually
(same folder where you have saved your program) a file will be copied with new name

How to Rename file using PHP

rename( ) function is used to rename file.
Syntax

Eg

Output
Check your folder manually
(same folder where you have saved your program) a file will be renamed

Checks whether a file or directory exists

file_exists( ) function is used to check file or directory existence.
Syntax

Eg

Output
It returns true(1) if file exists
otherwise return false(blank screen)


Check size of the file in PHP

filesize( ) function is used to check file size.
Syntax

Eg

Output
0 Bytes

Check Path of the file in PHP

realpath( ) function is used to check real path of the file.
Syntax

Eg

Output
C:xampplitehtdocsYoufProjectfileName with extension
//OR
C:wampwwwYoufProjectfileName with extension



  • BalaNagaPrasad M

    Hi Sanjeev,
    Its very Nice Site. You are giving Good information about PHP and HTML.
    Thank you Sanjeev. 🙂

  • saranyagangadharan

    I WANT PROGRAM IN PHP MYSQL FOR DISPLAYING CITIES BY SELECTING A STATE, all cities and states must be fetch from my sql..

  • saranyagangadharan

    thank u but i have a doubt why we are using ajax here? can u pls suggest a simple code without ajax for the same concept

  • Chaitanya Bhatt

    Hello sir… Can I get the upload popup code ..???

  • jai

    hello sir. how can connect our database and other database using php ? can you send me code Plz

    • Hello Jai
      can you tell me more about your query….

  • Ram Moorthy

    i need this page code job search page find job key word function

  • Dipen Parmar

    Thanks sir

  • Bashir Ahmad

    Hi MR. Sanjeev.
    how can i count a spicific letter in a row of sql.
    i mean i want to count p for present a for absent and s for sick in one row of sql table.

  • ankush. sharma

    if(isset($_POST[‘signin’]))
    {

    include “cs/config.php”;
    $UserEmail = mysqli_real_escape_string($db,$_POST[‘uLogin’]);
    $UserPassword = mysqli_real_escape_string($db,$_POST[‘uPassword’]);
    $resultlogin = mysqli_query($db,”call sp_user_signin(”,'”.$UserEmail.”‘,'”.$UserPassword.”‘,’USER_SIGNIN’)”);
    $db->close();
    if(mysqli_num_rows($resultlogin)>0)
    {
    while($row=mysqli_fetch_array($resultlogin))
    {
    $UId = $row[‘Subscriber_id’];
    $UName = $row[‘Billing_Name’];
    $UEmail = $row[‘billing_Email’];
    $URoleId = $row[‘role_id’];
    $UPwd = $row[‘password’];
    if($UserPassword==$UPwd)
    {
    // $_SESSION[‘userid’] = $UEmail;
    // $_SESSION[‘roleid’] = $URoleId;
    // $_SESSION[‘username’] = $UName;
    // $_SESSION[‘user_id’] = $UId;

    //set the cookies for 1 day, ie, 1*24*60*60 secs
    //change it to something like 30*24*60*60 to remember user for 30 days
    //set the cookies for 5 Minutes, ie, 60*5 secs

    setcookie(‘useremailid’, $UEmail, time() + 24*60*60, “/”);
    setcookie(‘roleid’, $URoleId, time() + 24*60*60, “/”);
    setcookie(‘username’, $UName, time() + 24*60*60, “/”);
    setcookie(‘userid’, $UId, time() + 24*60*60, “/”);

    if ($URoleId==”1″)
    {
    // $WebSite_URL=”location:”.$SiteURL.”index.html”;
    // header($WebSite_URL);
    // echo (”
    // window.alert(‘Succesfully Updated’)
    // window.location.href=’index.html’;
    // “);
    echo (”
    window.location.href=’index.html’;
    “);
    }
    if ($URoleId==”2″ || $URoleId==”3″)
    {
    // $WebSite_URL=”location:”.$SiteURL.”modify_booknotes.html”;
    // header($WebSite_URL);
    // echo (”
    // window.alert(‘Succesfully Updated’)
    // window.location.href=’modify_booknotes.html’;
    // “);
    echo (”
    window.location.href=’modify_booknotes.html’;
    “);
    }
    }
    else
    {
    echo “alert(‘Incorrect Password. Try Again!’)”;
    //$LoginMsg=’Incorrect Password. Try Again!’;
    }
    }
    }
    else
    {
    //echo “alert(‘Sorry this emailid is not registered with us!’)”;
    $LoginMsg=’Sorry this emailid is not registered with us!’;
    }
    }
    HELLO sir this is my login page ,in this we are showing incorrect password error using alertbox,sir can you please tell that how can i show my error using span in same page above sign in button?sir please give any solution

    • //echo “alert(‘Incorrect Password. Try Again!’)”;
      $LoginMsg=’Incorrect Password. Try Again!’;

      now use this variable “$LoginMsg” anywhere on the page
      like if u want to show error on footer

      • ankush. sharma

        yaah sir,its working but the probem is that when i m using this $Loginmsg variable on footer nd click on sign in then the all page reload but i want to focus on that page when i click on sign in.

  • Sohni saxena

    hlo sir..
    how to get file size in sql server