<html> <head><meta/><title>WP Plog Import Resources</title></head> <style> .ok { color:green; } .fail { color:red; } </style> <body> <?php /* wp_import_plog_resources (C)opyright 2006 by Volker Hartmann vurt@virtuatron.de http://www.virtuatron.de This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl.html */ // some path information * enter appropriate info here $plog_blog_id = "1"; $plog_gallery = "plog"."/gallery/".$plog_blog_id; $wp_dest = "blog"."/wp-content/uploads/"."imported"; //db parameters * enter appropriate info here $db_name = "db_name"; $db_user = "db_user"; $db_pass = "db_pass"; $db_host = "localhost"; $plog_table_prefix = "plog_"; // nothing to change below this line echo "<h1>Prerequisites</h1>"; //Connect to db $db = mysql_connect($db_host, $db_user, $db_pass) or die("<p class='fail'>Connect to db failed</p>" . mysql_error()); echo "<p class='ok'>Connection to db established.</p>"; ob_flush(); //select db mysql_select_db($db_name) or die("<p class='fail'>Failed selecting db</p>" . mysql_error()); echo "<p class='ok'>Successfully selected database ".$db_name."</p>"; ob_flush(); //Query db $query_string = "SELECT id,file_name FROM ".$plog_table_prefix."gallery_resources"; $result = mysql_query($query_string, $db) or die("<p class='fail'>Failed to query db</p>" . mysql_error()); echo "<p class='ok'>Query successful. Rows: ".mysql_num_rows($result)."</p>"; ob_flush(); //Move Files echo "<h1>Copying files...</h1>"; while($row = mysql_fetch_row($result)){ //get the file extension $dotpos = strrpos($row[1], "."); $file_ext = substr($row[1], -(strlen($row[1]) - strrpos($row[1], "."))); if (copy($plog_gallery."/".$plog_blog_id."-".$row[0].$file_ext, $wp_dest."/".$row[1])) { echo "<p class='ok'>Successfully copied file ".$plog_gallery."/".$plog_blog_id."-".$row[0].$file_ext." to ".$wp_dest."/".$row[1].".</p>"; ob_flush(); } else { echo "<p class='fail'>Failed to copy file ".$plog_gallery."/".$plog_blog_id."-".$row[0].$file_ext." to ".$wp_dest."/".$row[1].".</p>"; ob_flush(); } } echo "Done"; ?> </body> </html>