Axem Posted March 27, 2008 Share Posted March 27, 2008 can anyone take a look at this and let me know what i'm doing wrong? this script is supposed to take filenames from a txt file and make seperate folders based off of whats in the txt document, but for some reason its only ever making the last file in the txt with this code. can anyone help me? <?php $names = file('names.txt'); chdir("share/"); foreach($names as $name) { chdir("../"); mkdir("share/{$name}"); copy('setup.exe',"share/{$name}/setup.exe"); $till = mt_rand(10000,100000); for ($i = 0; $i < $till; $i++) { $data .= chr(mt_rand(32,126)); } file_put_contents("share/{$name}/setup.cab",$data); $data = ""; chdir("share/"); exec("7z a -r {$name}.zip {$name}"); } ?> Link to comment https://forums.phpfreaks.com/topic/98123-need-some-help-with-this-code/ Share on other sites More sharing options...
Cep Posted March 27, 2008 Share Posted March 27, 2008 You need to trim the directory name like this, <?php $directories = file('names.txt'); foreach($directories as $dir) { $dir = trim($dir); if (file_exists("./share/{$dir}")===false) { mkdir("./share/{$dir}"); } } ?> Link to comment https://forums.phpfreaks.com/topic/98123-need-some-help-with-this-code/#findComment-501987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.