file - How to create folder with PHP code? -
can create folder php code? want whenever new user create new account folder automatically creates , php file created.is possible?
purely basic folder creation
<?php mkdir("testing"); ?>
<= this, creates folder called "testing".
basic file creation
<?php $file = fopen("test.txt","w"); echo fwrite($file,"hello world. testing!"); fclose($file); ?>
use a
or a+
switch add/append file.
edit:
this version create file , folder @ same time , show on screen after.
<?php // change name below folder want $dir = "new_folder_name"; $file_to_write = 'test.txt'; $content_to_write = "the content"; if( is_dir($dir) === false ) { mkdir($dir); } $file = fopen($dir . '/' . $file_to_write,"w"); // different way write content // fwrite($file,"hello world."); fwrite($file, $content_to_write); // closes file fclose($file); // show created file created folder on screen include $dir . '/' . $file_to_write; ?>
Comments
Post a Comment