Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Mirrors new uploads silently to several backup domains - Simple! WordPress

  • SOLVED

I have <strong>3 different websites on 3 different shared-servers/vps.</strong> I want...

<strong>website#1 to act as the mirror/backup for ALL uploaded files.
website#2 should only backup the images (png,gif, jpeg).
website#3 should only backup the .psp, .psd, .mp3, .flv, and .mp4 files.</strong>

The backup websites should be able to create their own folders so that it matches the same folders as the main website. "wp-content/uploads/<strong>2010/01</strong>"

Please take a look at the related post below so you can see the code that I use on my website.

RELATED POST: [[LINK href="http://wpquestions.com/question/show/id/752"]]http://wpquestions.com/question/show/id/752[[/LINK]]

THIS IS THE CODE THAT WE HAVE ALREADY (working). It mirrors all uploads silently to our backup website#1. Now I need to improve this plugin so I can backup only CERTAIN files to website#2 and website#3.

plugin: uploadmirror/uploadmirror.php
<?php

/*

Plugin Name: Automatic Upload Mirror

Plugin URI:

Description:

Author:

Version: 1.0

Author URI:

*/





add_filter('wp_handle_upload', 'uploadmirror_main');

add_filter('wp_create_thumbnail', 'uploadmirror_main');

add_filter('image_make_intermediate_size', 'uploadmirror_main');



function uploadmirror_main($file) {



$uploads = wp_upload_dir();

$uploads['file'] = (is_string($file) ? $file : $file['url']);

$uploads['dir'] = (is_string($file) ? str_replace($uploads['basedir'], '', $uploads['file']) : str_replace($uploads['baseurl'], '', $uploads['file']));



// Fix url for thumbnails

$uploads['file'] = str_replace($uploads['path'], $uploads['url'], $uploads['file']);



foreach (array('uploadmirror_domain', 'uploadmirror_domain1', 'uploadmirror_domain2') as $option_name)

{

if (get_option($option_name) !== false) {



$ch = curl_init();

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, 'file=' . $uploads['file'] . '&dir=' . $uploads['dir']);

curl_setopt($ch, CURLOPT_URL, get_option($option_name));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$postResult = curl_exec($ch);



curl_close($ch);

}

}



return $file;



}





//Dashboard Menus



add_action('admin_menu', array('uploadmirror_admin_content', 'menu'));





class uploadmirror_admin_content {



function menu() {

add_options_page('Automatic Upload Mirror', 'Automatic Upload Mirror', 8, __FILE__, array('uploadmirror_admin_content', 'modify'));

}



function modify() {

if (!empty($_POST['do'])) {

foreach (array('uploadmirror_domain', 'uploadmirror_domain1', 'uploadmirror_domain2') as $option_name)

{

$newvalue = $_POST[$option_name];

if (get_option($option_name) != $newvalue) {

update_option($option_name, $newvalue);

} else {

$deprecated=' ';

$autoload='no';

add_option($option_name, $newvalue, $deprecated, $autoload);

}

}



if (!empty($error))

{

echo '<div class="error fade">' . nl2br($error) . '</div>';

}

else

{

echo '<div class="updated fade">Settings saved.</div>';

}

}



?>



<div class="wrap">



<h2>Automatic Upload Mirrors</h2>



<form action="" method="post" enctype="multipart/form-data">



<table class="widefat">



<tbody>



<tr>



<td>Path to filedump script #1</td>



<td><input type="text" value="<?php echo get_option('uploadmirror_domain', ''); ?>" name="uploadmirror_domain" style="width: 100%;" /></td>



</tr>



<tr>



<td>Path to filedump script #2</td>



<td><input type="text" value="<?php echo get_option('uploadmirror_domain1', ''); ?>" name="uploadmirror_domain1" style="width: 100%;" /></td>



</tr>



<tr>



<td>Path to filedump script #3</td>



<td><input type="text" value="<?php echo get_option('uploadmirror_domain2', ''); ?>" name="uploadmirror_domain2" style="width: 100%;" /></td>



</tr>



</tbody>



</table>



<input class="button-primary" name="do" value="Submit" class="button" type="submit" />



&nbsp;&nbsp;



<input name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" type="button" />



</form>



</div>



<?php



}

}

?>



And here's the code for the accompanying 'helper' file that downloads the uploads on the remote server:
website#1 /wp-content/uploads/filedump.php
<?php

function vWritePageToFile($readurl)

{

if (!$readurl)

{

print "No file specified.";

return false;

}



$dir = $_POST['dir'];

$parts = explode('/', $dir);

$file = array_pop($parts);

$dir = dirname(__FILE__);



foreach ($parts as $part)

{

if (!empty($part))

{

if (!is_dir($dir .= "/$part"))

{

mkdir($dir);

}

}

}



$ch = curl_init($readurl);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

$rawdata = curl_exec($ch);

curl_close($ch);



if (file_exists("$dir/$file"))

{

unlink("$dir/$file");

}



$fp = fopen("$dir/$file", 'x');

fwrite($fp, $rawdata);

fclose($fp);

}



if (isset($_POST['file']))

{

vWritePageToFile($_POST['file']);

}

else

{

die("No file specified.");

}

?>

Answers (1)

2010-11-06

Tobias Nyholm answers:

Didnt Jonah Schulte solve your problem before?


Andrew C comments:

I am trying to improve the plugin we already have.


Tobias Nyholm comments:

Try this! I modified uploadmirror_main() and added a sendPost function.
The if-statements contains an array with valid file extensions. There is one thing Im uncertain about... The call to pathinfo() should be an absolute path to the uploaded file. I don't know if $file is a valid input. You must double check that.

function uploadmirror_main($file) {

$uploads = wp_upload_dir();
$uploads['file'] = (is_string($file) ? $file : $file['url']);
$uploads['dir'] = (is_string($file) ? str_replace($uploads['basedir'], '', $uploads['file']) : str_replace($uploads['baseurl'], '', $uploads['file']));

// Fix url for thumbnails
$uploads['file'] = str_replace($uploads['path'], $uploads['url'], $uploads['file']);

//$file should be the full (absulute) path to the file.
$fileDetails = pathinfo($file);
$ext = strtolower($fileDetails["extension"]);

$postData='file=' . $uploads['file'] . '&dir=' . $uploads['dir'];

//Backup ALL
if(get_option('uploadmirror_domain') !== false){
sendPost(get_option('uploadmirror_domain'),$postData);
}

//For site 2, take some images
if(get_option('uploadmirror_domain1') !== false && in_array($ext,array("png","gif","jpeg","jpg"))){
sendPost(get_option('uploadmirror_domain1'),$postData);
}

//site 3, some other files
if(get_option('uploadmirror_domain2') !== false && in_array($ext,array('psp','psd', 'mp3', 'flv', 'mp4'))){
sendPost(get_option('uploadmirror_domain2'),$postData);
}

return $file;

}

/**
* send a curl post
*/
function sendPost($url, $postfields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_URL, get_option($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

curl_close($ch);

return $postResult;
}



Andrew C comments:

the modified code you provided did not give me an option to enter in the "absolute path" to my other script located on the other vps. It should be located under "settings" in the admin section of the wordpress.

your screenshot: http://i54.tinypic.com/2rm0ft4.png

old working page: http://i52.tinypic.com/2j4qydk.png
url to enter absolute path: /wp-admin/options-general.php?page=uploadmirror/uploadmirror.php


Tobias Nyholm comments:

You should not overwrite everything in uploadmirror.php.. Just one function. Here is the complete uploadmirror.php:

<?php

/*
Plugin Name: Automatic Upload Mirror
Plugin URI:
Description:
Author:
Version: 1.0
Author URI:
*/


add_filter('wp_handle_upload', 'uploadmirror_main');
add_filter('wp_create_thumbnail', 'uploadmirror_main');
add_filter('image_make_intermediate_size', 'uploadmirror_main');

function uploadmirror_main($file) {

$uploads = wp_upload_dir();
$uploads['file'] = (is_string($file) ? $file : $file['url']);
$uploads['dir'] = (is_string($file) ? str_replace($uploads['basedir'], '', $uploads['file']) : str_replace($uploads['baseurl'], '', $uploads['file']));

// Fix url for thumbnails
$uploads['file'] = str_replace($uploads['path'], $uploads['url'], $uploads['file']);

//$file should be the full (absulute) path to the file.
$fileDetails = pathinfo($file);
$ext = strtolower($fileDetails["extension"]);

$postData='file=' . $uploads['file'] . '&dir=' . $uploads['dir'];

//Backup ALL
if(get_option('uploadmirror_domain') !== false){
sendPost(get_option('uploadmirror_domain'),$postData);
}

//For site 2, take some images
if(get_option('uploadmirror_domain1') !== false && in_array($ext,array("png","gif","jpeg","jpg"))){
sendPost(get_option('uploadmirror_domain1'),$postData);
}

//site 3, some other files
if(get_option('uploadmirror_domain2') !== false && in_array($ext,array('psp','psd', 'mp3', 'flv', 'mp4'))){
sendPost(get_option('uploadmirror_domain2'),$postData);
}

return $file;

}

/**
* send a curl post
*/
function sendPost($url, $postfields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_URL, get_option($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

curl_close($ch);

return $postResult;
}

//Dashboard Menus

add_action('admin_menu', array('uploadmirror_admin_content', 'menu'));


class uploadmirror_admin_content {

function menu() {
add_options_page('Automatic Upload Mirror', 'Automatic Upload Mirror', 8, __FILE__, array('uploadmirror_admin_content', 'modify'));
}

function modify() {
if (!empty($_POST['do'])) {
foreach (array('uploadmirror_domain', 'uploadmirror_domain1', 'uploadmirror_domain2') as $option_name)
{
$newvalue = $_POST[$option_name];
if (get_option($option_name) != $newvalue) {
update_option($option_name, $newvalue);
} else {
$deprecated=' ';
$autoload='no';
add_option($option_name, $newvalue, $deprecated, $autoload);
}
}

if (!empty($error))
{
echo '<div class="error fade">' . nl2br($error) . '</div>';
}
else
{
echo '<div class="updated fade">Settings saved.</div>';
}
}

?>

<div class="wrap">
<h2>Automatic Upload Mirrors</h2>
<form action="" method="post" enctype="multipart/form-data">
<table class="widefat">
<tbody>
<tr>
<td>Path to filedump script #1</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain', ''); ?>" name="uploadmirror_domain" style="width: 100%;" /></td>
</tr>
<tr>
<td>Path to filedump script #2</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain1', ''); ?>" name="uploadmirror_domain1" style="width: 100%;" /></td>
</tr>
<tr>
<td>Path to filedump script #3</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain2', ''); ?>" name="uploadmirror_domain2" style="width: 100%;" /></td>
</tr>
</tbody>
</table>
<input class="button-primary" name="do" value="Submit" class="button" type="submit" />
&nbsp;&nbsp;
<input name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" type="button" />
</form>
</div>

<?php

}
}
?>


Andrew C comments:

error message: http://i51.tinypic.com/ve681v.png
line 27: http://i52.tinypic.com/2rm86fp.png
settings page: http://i55.tinypic.com/t52fqc.png (only have 2 filled in with absolute path at the moment)


Tobias Nyholm comments:

okey. Se line 26.

Try to replace line 27 and 28 with:
$ext=strtolower($file['type']);

if that does not work please write:
die(print_r($file,true).print_r($uploads,true));
at line 25 and give me the output.


Andrew C comments:

replaced line 27 and 28 with: <strong>$ext=strtolower($file['type']);</strong>

no error message. upload worked on local website, but did not mirror to offsite vps/website.


line 25: <strong>die(print_r($file,true).print_r($uploads,true));</strong>
error message: [[LINK href="http://i54.tinypic.com/ff4zg5.png"]]http://i54.tinypic.com/ff4zg5.png[[/LINK]]

Array (
[file] => /home/n2s/public_html/blog/wp-content/uploads/2010/11/2djum1zddddddd.png
[url] => http://blog.mywebsite.com/wp-content/uploads/2010/11/2djum1zddddddd.png
[type] => image/png )

Array ( [path] => /home/n2s/public_html/blog/wp-content/uploads/2010/11
[url] => http://blog.mywebsite.com/wp-content/uploads/2010/11
[subdir] => /2010/11
[basedir] => /home/n2s/public_html/blog/wp-content/uploads
[baseurl] => http://blog.mywebsite.com/wp-content/uploads
[error] => [file] => http://blog.mywebsite.com/wp-content/uploads/2010/11/2djum1zddddddd.png
[dir] => /2010/11/2djum1zddddddd.png )

*I changed my url above so it does not cache in google index -- the screenshot shows you the correct url*


Andrew C comments:

My original code does not work 100%. It only backs up to website#1.


Tobias Nyholm comments:

This is the complete mirrorupload.php. If your original code works, this should also work. I have made a smaller change on line 27 since last post.

Remember to put the filedump.php on your site #2 and #3.



<?php

/*
Plugin Name: Automatic Upload Mirror
Plugin URI:
Description:
Author:
Version: 1.0
Author URI:
*/


add_filter('wp_handle_upload', 'uploadmirror_main');
add_filter('wp_create_thumbnail', 'uploadmirror_main');
add_filter('image_make_intermediate_size', 'uploadmirror_main');

function uploadmirror_main($file) {

$uploads = wp_upload_dir();
$uploads['file'] = (is_string($file) ? $file : $file['url']);
$uploads['dir'] = (is_string($file) ? str_replace($uploads['basedir'], '', $uploads['file']) : str_replace($uploads['baseurl'], '', $uploads['file']));

// Fix url for thumbnails
$uploads['file'] = str_replace($uploads['path'], $uploads['url'], $uploads['file']);

//$file should be the full (absolute) path to the file.
$fileDetails = pathinfo($file['file']);
$ext = strtolower($fileDetails["extension"]);

$postData='file=' . $uploads['file'] . '&dir=' . $uploads['dir'];

//Backup ALL
if(get_option('uploadmirror_domain') !== false){
sendPost(get_option('uploadmirror_domain'),$postData);
}

//For site 2, take some images
if(get_option('uploadmirror_domain1') !== false && in_array($ext,array("png","gif","jpeg","jpg"))){
sendPost(get_option('uploadmirror_domain1'),$postData);
}

//site 3, some other files
if(get_option('uploadmirror_domain2') !== false && in_array($ext,array('psp','psd', 'mp3', 'flv', 'mp4'))){
sendPost(get_option('uploadmirror_domain2'),$postData);
}

return $file;

}

/**
* send a curl post
*/
function sendPost($url, $postfields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_URL, get_option($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

curl_close($ch);

return $postResult;
}

//Dashboard Menus

add_action('admin_menu', array('uploadmirror_admin_content', 'menu'));


class uploadmirror_admin_content {

function menu() {
add_options_page('Automatic Upload Mirror', 'Automatic Upload Mirror', 8, __FILE__, array('uploadmirror_admin_content', 'modify'));
}

function modify() {
if (!empty($_POST['do'])) {
foreach (array('uploadmirror_domain', 'uploadmirror_domain1', 'uploadmirror_domain2') as $option_name)
{
$newvalue = $_POST[$option_name];
if (get_option($option_name) != $newvalue) {
update_option($option_name, $newvalue);
} else {
$deprecated=' ';
$autoload='no';
add_option($option_name, $newvalue, $deprecated, $autoload);
}
}

if (!empty($error))
{
echo '<div class="error fade">' . nl2br($error) . '</div>';
}
else
{
echo '<div class="updated fade">Settings saved.</div>';
}
}

?>

<div class="wrap">
<h2>Automatic Upload Mirrors</h2>
<form action="" method="post" enctype="multipart/form-data">
<table class="widefat">
<tbody>
<tr>
<td>Path to filedump script #1</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain', ''); ?>" name="uploadmirror_domain" style="width: 100%;" /></td>
</tr>
<tr>
<td>Path to filedump script #2</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain1', ''); ?>" name="uploadmirror_domain1" style="width: 100%;" /></td>
</tr>
<tr>
<td>Path to filedump script #3</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain2', ''); ?>" name="uploadmirror_domain2" style="width: 100%;" /></td>
</tr>
</tbody>
</table>
<input class="button-primary" name="do" value="Submit" class="button" type="submit" />
&nbsp;&nbsp;
<input name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" type="button" />
</form>
</div>

<?php

}
}
?>


Andrew C comments:

nothing happens. it uploads only to my website and does not get mirrored anywhere.

I only need to mirror my images to one vps.. and my media files to another vps for backup. Is there another way to do this that you can suggest?


Tobias Nyholm comments:

Actually, I dont know an other solution than the one we are trying right now. Due obvious reason I cant debug on my own.

Try to write error messages in the if statements.

<?php

/*
Plugin Name: Automatic Upload Mirror
Plugin URI:
Description:
Author:
Version: 1.0
Author URI:
*/


add_filter('wp_handle_upload', 'uploadmirror_main');
add_filter('wp_create_thumbnail', 'uploadmirror_main');
add_filter('image_make_intermediate_size', 'uploadmirror_main');

function uploadmirror_main($file) {

$uploads = wp_upload_dir();
$uploads['file'] = (is_string($file) ? $file : $file['url']);
$uploads['dir'] = (is_string($file) ? str_replace($uploads['basedir'], '', $uploads['file']) : str_replace($uploads['baseurl'], '', $uploads['file']));

// Fix url for thumbnails
$uploads['file'] = str_replace($uploads['path'], $uploads['url'], $uploads['file']);

//$file should be the full (absolute) path to the file.
$fileDetails = pathinfo($file['file']);
$ext = strtolower($fileDetails["extension"]);

$postData='file=' . $uploads['file'] . '&dir=' . $uploads['dir'];

//Backup ALL
if(get_option('uploadmirror_domain') !== false){
sendPost(get_option('uploadmirror_domain'),$postData);
}

//For site 2, take some images
if(get_option('uploadmirror_domain1') !== false && in_array($ext,array("png","gif","jpeg","jpg"))){
sendPost(get_option('uploadmirror_domain1'),$postData);
die("sent to site2");
}

//site 3, some other files
if(get_option('uploadmirror_domain2') !== false && in_array($ext,array('psp','psd', 'mp3', 'flv', 'mp4'))){
sendPost(get_option('uploadmirror_domain2'),$postData);
die("Sent to site 3");
}

die("file ending:".$ext);
return $file;

}

/**
* send a curl post
*/
function sendPost($url, $postfields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_URL, get_option($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

curl_close($ch);

return $postResult;
}

//Dashboard Menus

add_action('admin_menu', array('uploadmirror_admin_content', 'menu'));


class uploadmirror_admin_content {

function menu() {
add_options_page('Automatic Upload Mirror', 'Automatic Upload Mirror', 8, __FILE__, array('uploadmirror_admin_content', 'modify'));
}

function modify() {
if (!empty($_POST['do'])) {
foreach (array('uploadmirror_domain', 'uploadmirror_domain1', 'uploadmirror_domain2') as $option_name)
{
$newvalue = $_POST[$option_name];
if (get_option($option_name) != $newvalue) {
update_option($option_name, $newvalue);
} else {
$deprecated=' ';
$autoload='no';
add_option($option_name, $newvalue, $deprecated, $autoload);
}
}

if (!empty($error))
{
echo '<div class="error fade">' . nl2br($error) . '</div>';
}
else
{
echo '<div class="updated fade">Settings saved.</div>';
}
}

?>

<div class="wrap">
<h2>Automatic Upload Mirrors</h2>
<form action="" method="post" enctype="multipart/form-data">
<table class="widefat">
<tbody>
<tr>
<td>Path to filedump script #1</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain', ''); ?>" name="uploadmirror_domain" style="width: 100%;" /></td>
</tr>
<tr>
<td>Path to filedump script #2</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain1', ''); ?>" name="uploadmirror_domain1" style="width: 100%;" /></td>
</tr>
<tr>
<td>Path to filedump script #3</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain2', ''); ?>" name="uploadmirror_domain2" style="width: 100%;" /></td>
</tr>
</tbody>
</table>
<input class="button-primary" name="do" value="Submit" class="button" type="submit" />
&nbsp;&nbsp;
<input name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" type="button" />
</form>
</div>

<?php

}
}
?>



What will this code say?
"Sent to siteX" or "File ending: XXX".


Andrew C comments:

uploaded: gif / png files
output: sent to site2
screenshot: http://i56.tinypic.com/1zg7r5k.png
settings: http://i54.tinypic.com/1tptfk.png
ftp login + file directory of site#2: http://i52.tinypic.com/20i6fmh.png

I also tried moving around the settings and trying to upload an .mp3. that didn't work either.


Tobias Nyholm comments:

because of: "sent to site2"
A post have been sent. The error is on site 2. Check file permissions etc...


Andrew C comments:

permissions are correct. i switched around the sites.. only website#1 works by ITSELF. The original code doesnt work for website#2 or website#3


Andrew C comments:

Tobias I am willing to pay, but the plugin doesnt seem to work. I am closing this project. /=

Maybe you can do another plugin instead? I need to REQUIRE a thumbnail on every post. can you create a plugin that doesn't allow you to PUBLISH the article without a thumbnail? It should allow you to SAVE AS DRAFT though.


Tobias Nyholm comments:

Hi. Sorry to hear you closing your project. If you want to have a last try, here is the code. It only send your files to one site depending on the file extention:

<?php

/*
Plugin Name: Automatic Upload Mirror
Plugin URI:
Description:
Author:
Version: 1.0
Author URI:
*/


add_filter('wp_handle_upload', 'uploadmirror_main');
add_filter('wp_create_thumbnail', 'uploadmirror_main');
add_filter('image_make_intermediate_size', 'uploadmirror_main');

function uploadmirror_main($file) {

$uploads = wp_upload_dir();
$uploads['file'] = (is_string($file) ? $file : $file['url']);
$uploads['dir'] = (is_string($file) ? str_replace($uploads['basedir'], '', $uploads['file']) : str_replace($uploads['baseurl'], '', $uploads['file']));

// Fix url for thumbnails
$uploads['file'] = str_replace($uploads['path'], $uploads['url'], $uploads['file']);

//$file should be the full (absulute) path to the file.
$fileDetails = pathinfo($file['file']);
$ext = strtolower($fileDetails["extension"]);

$postData='file=' . $uploads['file'] . '&dir=' . $uploads['dir'];



//For site 2, take some images
if(get_option('uploadmirror_domain1') !== false && in_array($ext,array("png","gif","jpeg","jpg"))){
sendPost(get_option('uploadmirror_domain1'),$postData);
}

//site 3, some other files
elseif(get_option('uploadmirror_domain2') !== false && in_array($ext,array('psp','psd', 'mp3', 'flv', 'mp4'))){
sendPost(get_option('uploadmirror_domain2'),$postData);
}
//Backup ALL
elseif(get_option('uploadmirror_domain') !== false){
sendPost(get_option('uploadmirror_domain'),$postData);
}

return $file;

}

/**
* send a curl post
*/
function sendPost($url, $postfields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_URL, get_option($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

curl_close($ch);

return $postResult;
}

//Dashboard Menus

add_action('admin_menu', array('uploadmirror_admin_content', 'menu'));


class uploadmirror_admin_content {

function menu() {
add_options_page('Automatic Upload Mirror', 'Automatic Upload Mirror', 8, __FILE__, array('uploadmirror_admin_content', 'modify'));
}

function modify() {
if (!empty($_POST['do'])) {
foreach (array('uploadmirror_domain', 'uploadmirror_domain1', 'uploadmirror_domain2') as $option_name)
{
$newvalue = $_POST[$option_name];
if (get_option($option_name) != $newvalue) {
update_option($option_name, $newvalue);
} else {
$deprecated=' ';
$autoload='no';
add_option($option_name, $newvalue, $deprecated, $autoload);
}
}

if (!empty($error))
{
echo '<div class="error fade">' . nl2br($error) . '</div>';
}
else
{
echo '<div class="updated fade">Settings saved.</div>';
}
}

?>

<div class="wrap">
<h2>Automatic Upload Mirrors</h2>
<form action="" method="post" enctype="multipart/form-data">
<table class="widefat">
<tbody>
<tr>
<td>Path to filedump script #1</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain', ''); ?>" name="uploadmirror_domain" style="width: 100%;" /></td>
</tr>
<tr>
<td>Path to filedump script #2</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain1', ''); ?>" name="uploadmirror_domain1" style="width: 100%;" /></td>
</tr>
<tr>
<td>Path to filedump script #3</td>
<td><input type="text" value="<?php echo get_option('uploadmirror_domain2', ''); ?>" name="uploadmirror_domain2" style="width: 100%;" /></td>
</tr>
</tbody>
</table>
<input class="button-primary" name="do" value="Submit" class="button" type="submit" />
&nbsp;&nbsp;
<input name="cancel" value="Cancel" class="button" onclick="javascript:history.go(-1)" type="button" />
</form>
</div>

<?php

}
}
?>


<blockquote>Maybe you can do another plugin instead? I need to REQUIRE a thumbnail on every post. can you create a plugin that doesn't allow you to PUBLISH the article without a thumbnail? It should allow you to SAVE AS DRAFT though.</blockquote>
Sure. The plugin will be called require-thumbnail and be available as soon as wordpress accepts it.
Maybe Tuesday..