Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //// CONNECT TO DATABASE ////
- include 'h/1.c/db_connect.php';
- include 'i/global_variables.php';
- /////////////////////////////
- //Store the table name to make it easy to move this code to another Site
- $table_name = "antiquesnow_ads";
- //Base URL for downloads. Trailing "/" is required
- $base_url = "http://www.antiques-now.co.uk/antiques-for-sale-images/";
- //SQL Query to get all picture filenames from teh DB
- $result_category = mysql_query("SELECT * FROM $table_name WHERE live >= 1 AND ((pic_name IS NOT NULL) OR (pic_name != ''))");
- //store the field names in an array so we can iterate through them with "foreach"
- $field_names = array("pic_name", "pic_name2", "pic_name3", "pic_name4");
- //Container for the " " separated list of all the image names
- $p_wget_strings = array();
- for ($i = 0; $i < 20; $i++)
- { $p_wget_strings[$i] = "";
- }
- //Counter
- $counter = 0;
- $p_counter = 0;
- //Loop through all the results from the database, and build the string of filenames
- while ( $row = mysql_fetch_array($result_category) )
- { foreach ($field_names as $field_name)
- { //Store the value of this field for this record
- $field_value = $row[$field_name];
- //Check if this field_value is NULL or Emtpy
- if ( $field_value != NULL
- && $field_value != ""
- )
- { //Remove any spaces from the field_value
- $field_value = str_replace(" ", "\\ ", $field_value);
- //Add the field_value to the great big string, with the url prefix
- $p_wget_strings[$p_counter] .= " \\\n".$base_url.$field_value;
- //Increment parrallel counter
- $p_counter++;
- //limit to 20 parrallel wget instances
- if ($p_counter == 20)
- { $p_counter = 0;
- }
- //Increment Counter
- $counter++;
- }
- }
- }
- //build the script
- $script_string = "echo About to copy $counter items from $base_url. Y to continue [n]\n";
- $script_string .= "read\n";
- $script_string .= "if [ \$REPLY = \"Y\" ]\n";
- $script_string .= "then\n";
- $counter = 0;
- foreach ($p_wget_strings as $wget_instance)
- { $counter ++;
- $script_string .= " wget $wget_instance -o `date +%d-%m-%Y_%H:%M:%S.%N`__logfile_$counter &\n";
- }
- $script_string .= "fi\n\n";
- //output to the browser
- echo $script_string;
- //Flush output cache
- flush();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement