nahydy Posted December 17, 2008 Share Posted December 17, 2008 Hi, I have a little question: how can i create a directorie with php because this line of code seems not working: mkdir('/var/www/toto',0777,true); Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/ Share on other sites More sharing options...
[email protected] Posted December 17, 2008 Share Posted December 17, 2008 Is it giving you any errors or what? Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/#findComment-717587 Share on other sites More sharing options...
nahydy Posted December 17, 2008 Author Share Posted December 17, 2008 No it don't show any error, and there is no directorie created into the /var/www. I created a directorie test into the /var/www and change owner to www-data. But when i tried to make this mkdir('/var/www/test/toto',0777,true); there is no toto into my directorie. I don't see where the problem is. Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/#findComment-717672 Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 Try this it works this end...... <?php $dir_name='redarrow/'; $sub_directory='redarrow_files'; $create_dir=@mkdir("$dir_name"); @chmod('0777'.$create_dir); $create_dir2=@mkdir("$dir_name"."$sub_directory"); @chmod('0777'.$create_dir2); echo "diretory $dir_name $sub_directory made!"; exit; ?> Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/#findComment-717699 Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 Here another interesting one for u. <?php $dir_name='redarrow/'; $create_dir=@mkdir("$dir_name"); @chmod('0777'.$create_dir); $f=array("a","b","c"); foreach($f as $sub_directory){ $create_dir2=@mkdir("$dir_name"."$sub_directory"); } @chmod('0777'.$create_dir2); exit; ?> Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/#findComment-717702 Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 <?php // user name would use user id ....... $d=array('redarrow','john','paul','sharon','lisa'); foreach($d as $dir_name){ $create_dir=@mkdir("$dir_name"); @chmod('0777'.$create_dir); //inside user name $f=array("photo_album","fav_pictures","drawings","personal_pictures","dirty_pictures"); foreach($f as $sub_directory){ $create_dir2=@mkdir("$dir_name/"."$sub_directory"); } } @chmod('0777'.$create_dir2); exit; ?> Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/#findComment-717715 Share on other sites More sharing options...
nahydy Posted December 17, 2008 Author Share Posted December 17, 2008 I tried the two methods but none of them created my directories. But i tried this and worked well: shell_exec('mkdir /var/www/test/toto'); I have a question: why using @ before chmod and mkdir? And thank you for helping me. Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/#findComment-717720 Share on other sites More sharing options...
[email protected] Posted December 17, 2008 Share Posted December 17, 2008 I tried the two methods but none of them created my directories. But i tried this and worked well: shell_exec('mkdir /var/www/test/toto'); I have a question: why using @ before chmod and mkdir? And thank you for helping me. It supresses any errors that come up. Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/#findComment-717727 Share on other sites More sharing options...
redarrow Posted December 17, 2008 Share Posted December 17, 2008 @ << All it does is suppress the error from the php.ini engine. in other words dont want to see the error, some functions like mkdir and others give errors but it not a coding error just the way it is....... Dont this for fun for you and me m8. <?php $d=array('redarrow','john','paul','sharon','lisa'); foreach($d as $dir_name){ $create_dir=@mkdir("$dir_name"); @chmod('0777'.$create_dir); $f=array("photo_album","fav_pictures","drawings","personal_pictures","dirty_pictures"); foreach($f as $sub_directory){ $create_dir2=@mkdir("$dir_name/"."$sub_directory"); } } @chmod('0777'.$create_dir2); foreach($d as $directorys){ $path = $directorys; $dir_handle = @opendir($path) or die("Unable to open $path"); while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || $file == "index.php" ) continue; echo "Inside directory: $directorys has this file <a href=\"$file\">$file</a><br /> <br><br>"; } } closedir($dir_handle); ?> Link to comment https://forums.phpfreaks.com/topic/137345-solved-can-not-create-directories-with-mkdir/#findComment-717735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.