Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Create a file Using Php

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 446
    Comment on it

    Create a file Using Php

    In PHP,we can use the fopen() function to create a file.
    If we use fopen() on a file, it will create file(if that file does not exist) by given named.

    Syntax:

    fopen("testfile.txt", "Mode");
    Both arguments are required
    

    First arg:
    1.file name or path of the where we want to create.
    2.Required(if we missed, it throw Warning error like 'Warning: fopen(): Filename cannot be empty')

    Second arg:
    1.Mode of file in which you want to create.
    2.Required
    If we taken blank mode it throw Warning error like 'Warning: fopen(testfile.text): failed to open stream:
    Resource temporarily unavailable in /var/www/filehandling/createfile.php on line 8 Failed')

    if we missed Moode it throw Warning error like 'Warning: fopen() expects at least 2 parameters, 1 given in /var/www/filehandling/createfile.php on line 8 Failed'


    Example:

    <!--?php
    /*
     * Created By: Evon Tech
     * Date:30/4/2015
     */
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    $myfile = fopen('testfile.text','w');
    if ($myfile) {
        echo 'Cretaed';
    } else {
        echo 'Failed';
    }
    ?-->
    

    Note: If you will put file name without any extension, it created plane text document(MIME Type: text/plain) by default

 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: