I have a script that takes a variable, eg. elephant, and creates a directory structure in the form:
/public_html/animals/elephant
/public_html/animals/elephant/elephant_photos
And copies the files:
/public_html/animals/model/index.html /public_html/animals/elephant/index.html
/public_html/animals/model/model_photos/1.jpg /public_html/animals/elephant/elephant_photos/1.jpg
/public_html/animals/model/model_photos/2.jpg /public_html/animals/elephant/elephant_photos/2.jpg
The script has been working fine for a while now when it takes a single value from the form. But now I modified it so it takes an array of values from a TEXTAREA, and is supposed to iterate through them. Eg. a textarea could be filled as follows:
And the appropriate directory structure, etc. should be created for each.
But what happens is the LAST value (squirrel in this case) works ok, but the others create directories which are inaccessible via the web browser and even via FTP. I hope you understand. Here is the code I use:
interface.php
<h2>BULK Prepare Images</h2>
<form action="image_functions.php" method="POST">
<input type=hidden name='do' value='prepare_bulk'>
Input Values: <textarea name="h_name_bulk" type="text"></textarea>
<br><input type="submit">
</form>
image_functions.php
if ($do == 'prepare_bulk') {
$lines = split("\n", $h_name_bulk);
echo "<html>";
for ($line_idx=0; $line_idx<count($lines); $line_idx++) {
prepare_photo_filesystem($lines[$line_idx]);
echo "Created filesystem for<br>$lines[$line_idx]<br>";
}
echo "</html>";
}
.
.
.
function prepare_photo_filesystem($this_h_name) {
#copy relevant files needed for each variable's photo system
mkdir("$_SERVER[DOCUMENT_ROOT]/$this_h_name", 755);
copy("$_SERVER[DOCUMENT_ROOT]/model/photos/nophoto.jpg","$_SERVER[DOCUMENT_ROOT]/{$this_h_name}/photos/{$this_h_name}_1.jpg");
copy("$_SERVER[DOCUMENT_ROOT]/model/photos/nophoto.jpg","$_SERVER[DOCUMENT_ROOT]/{$this_h_name}/photos/{$this_h_name}_2.jpg");
copy("$_SERVER[DOCUMENT_ROOT]/model/EXAMPLE_index.html","$_SERVER[DOCUMENT_ROOT]/$this_h_name/index.html");
}
I hope this makes sense. Don't worry about the filenames as I just changed them hastily and may have made a few mistakes (I'm obviously not using animals in the real application but for example only! 🙂 ).