Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PHP File Functions

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 118
    Comment on it

    PHP Copying, Creating & Deleting files


    Copy file using PHP:- In PHP when we want to copy our file from source to destination then we have to use following syntax.

    Syntax:

    Bool copy (string $source, string $destination);
    

    Example:

    Echo Copy (source.txt,dest.txt);
    

    Create file using PHP:- In PHP when we want to create our file then we will use fopen(). In fopen() we will pass the name of file and also give the permission (read,write to that file). The syntax for fopen is

    Syntax

    fopen (string $filename, string $ mode);
    

    example:

    $fopenexample = fopen($fopenexample, 'w') or die("can't open file");
    

    Delete file using PHP:- In PHP when we want to delete our file then we will use unlink() function. In unlink() we will pass the name of file. The syntax of unlink is

    Syntax

    unlink (string $filename);
    

    Example:

    <?php
    $file = "unlink.txt";
    if (!unlink($file)){
     echo ("Error deleting $file");
    }
    else
    {
           echo ("Deleted $file");
    }
    ?> 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: