Create Folder and files in PHP

by Jayanthi 2012-09-17 14:37:23

Create Folder and files with set permissions in php

<?php

$foldername="QuaterReport";
for($i=1;$i<=3;$i++)
{
$subfolder="Month".$i;
$sdir="/home/xxxx/downloads/".$foldername."/".$subfolder;

if(is_dir($sdir)===false){
if (!mkdir($sdir, 0777, true)) {
echo "$foldername/$subfolder - Already Create it...<br>";
}
else{
chmod($sdir,0777);
echo "$foldername/$subfolder - Successfully created...<br>";
}
}
$lineadd="NewFile - Month".$i;
$filename = "new".$i."txt";

if($fp = fopen($sdir."/".$filename, "w"))
{
fwrite($fp, $lineadd);
fclose($fp);
echo "$foldername/$subfolder/$filename - Successfully created...<br>";
}
}
?>
922
like
0
dislike
0
mail
flag

You must LOGIN to add comments