Dec
05
2008

Custom new function mkfile()

Since i needed to write a script that would make a file if it doesn’t excists, i thought mkfile() would be a perfect name for it.

The only thing mkfile does is check if a file excists on the server, and if it doesn’t it would create it, and chmod it. 

Let me show you the code:

<?php 
    function mkfile($filename,$mode) { 
        if (!file_exists($filename)) { 
             $handle = fopen($filename,'w+'); 
             fclose($handle);
             chmod($filename,$mode); 
        } 
    } 
?>

This code simply creates a function that can easily be used by calling it this way:

<?php 
    mkfile('pages/myfile.php',0777); 
?>

Just simply insert the filename and the rights (mode) and you can create a file with your own function.
You can also add your own features to this function, but in my opinion it is already complete.

Note: Don’t forget to check the input in the mkfile() function. If you let users create files, you should at least know they wont enter scripts in it! But i made this function only for you’re own use!

Written by Rene Pot in: Sugestions | Tags: , , ,

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes