PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Tuesday 5 August 2014

Create Directory and text File using PHP

No comments :

We have been regularly in use of making directory using windows. and also text file.




Here is code which will help u to make folder and text files using php script.

<?php
$newdir='RuchiS';
$thisdir = getcwd();
echo "The Current Directory is ".$thisdir;
if(mkdir($thisdir . '/' . $newdir, 0777))
{
    $myfile = fopen($newdir.'/' ."newfile.txt", "w") or die("Unable to open file!");
    $txt = "Ruchi\n";
    fwrite($myfile, $txt);
    $txt = "Sanghvi\n";
    fwrite($myfile, $txt);
    fclose($myfile);
echo 'Directory has been created successfully...';
}
else
{
echo 'Failed to create directory...';
}
?>


The first line of code will be name of directory which you want to create in short,name of directory.Second line is for pointing current directory which u will create.

Here if condition will check wheather directory is made or not.and 777 will give write permission to folder.
under if condition text file will be created with fopen function.which will be in write mode.

In that text we can write text like Ruchi and Sanghvi. and fwrite function will write text into it.
 

No comments :

Post a Comment