Jump to content

need some help with this code


Axem

Recommended Posts

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

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}");
 }
    

}

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.