Search code examples
phpfopen

How to create a file that has no name but only extension in PHP?


I'm trying to create a file using PHP but the problem is that the needed file has no name but only an extension. How can I do it? The present code just doesn't make the file but it also doesn't give me an error.

fopen( '.extension', 'w' )or die( 'ERROR MESSAGE' );

Solution

  • Files with only an extension and no name are treated as hidden in unix. To list them, you might call ls -la inside the terminal.

    So the code you posted should just work fine. Note: you should always close the file opend with fopen!

    $f = fopen( '.extension', 'w' );
    if ($f) {
        fclose($f);
    }