MyBB Community Forums

Full Version: Download ALL attachments from your forum!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
<?php
if(!isset($_GET['start'])){
	$start1 = 0;
}else{
	$start1 = intval($_GET['start']);
}
$host = "localhost";
$user = "root";
$pass = "";
$name = "dbname";
$forumurl = "http://community.mybb.com";

$con = mysql_connect($host, $user, $pass);
mysql_select_db($name, $con);
$query = mysql_query("select * from `mybb_attachments` LIMIT {$start1} , 10");
$rows = $start1;
while($a = mysql_fetch_assoc($query)){
	echo "Downloading <a href=\"{$forumurl}/{$a['attachname']}\">{$a['filename']}</a>.........";
	$start = time();
	system("wget {$forumurl}/uploads/{$a['attachname']} -o {$a['filename']}",$output);
	$stop = time();
	echo "<font color=\"green\">Finished in ".intval($stop - $start)." seconds</font><br />\n";
	++$rows;
}
if($rows == 10){
	echo "Waiting...";
	echo '    <meta http-equiv="refresh" content="2;url=index.php?start='.intval($start1 + 10).'"> ';
}
?>

it will download all the files to the directory you put this script in. It will not keep the .attach format, but change back to it's original! (If for some reason you want to keep the .attach and keep everything in correct directories remove "-o {$a['filename']}" and put "-x" instead.

Enjoy :p
Very cool.
only if your server allows the system function, it is usually disabled as an "unsafe" function for security purposes.
I believe this is meant to be run from localhost via remote SQL?
I suppose that it is, but I like to run my tests on a matching setup. I could re-enable the system function for the time I was going to run that script I suppose.

However, if you already have the DB on your localhost, then why not FTP the whole uploads to your localhost and just run a rename script instead of doing a wget 10 files at a time?
I made this for use on my local computer (where i allowed system()) so i could get all of the attachments from my forum (for a backup of the original files)
Also, i no longer had FTP access to the site and all i had was the database connection. that's what made it more useful to me :p