Hello everyone..
I have a open source remote file upload script. It is called file snatcher. We can directly upload the files to our server from another server. But the problem is we can upload only one file at a time. I mean if you have many url, you have to enter the second url after first one finished. I have almost 500 url to upload in my server. So i need little correction in this script.
Instead of single url, i want to enter a bunch of url and upload it. I know it is a little correction something like "foreach" loop. But i don't know exactly how to correct it. Because i know php only little bit. So can anyone help me?. I have attached the source codes.

settings.php

/*settings.php*/
<?php
defined('_ALLOWINCLUDE') or die();

// Default destination to copy files too NO TRAILING SLASH!!
// If it is complete path, file be copied there ex: /home/public_html/FOLDER (Linux), C:\htdocs\FOLDER (Windows)
// If it is just a direcotory it will be copied to that directory in directory the script is in ex: /SnatcherFolder/FOLDER
$defaultDest = 'snatched';
	/*
	More examples
	If $defaultDest = ''; it will automatically copy to the `snatched` directory inside of the script's directory.
	If $defaultDest = 'files'; it will copy to `files` directory inside of the script's directory.
	*/

// If you want a password to be required
// Remember if you don't have a password anyone can copy a file to your server!
$password = ''; 

// URL to location of snatched files WITH OUT TRAILING SLASH
$URLDest = 'http://example.com/snatched';


// Put a limit for file size in kilobytes (1024KB is 1MB)
// For unlimited put 0
// Example $sizelimit = 25;
$sizelimit = 0;

?>

index.php

<?php
//File Snatcher 2.7
define('_ALLOWINCLUDE',0);
include 'settings.php';
$version = '2.7';
//////////////////////////////////////////////
//Do Not Change Below Here////////////////////
//////////////////////////////////////////////
if (function_exists('curl_init'))
{
	$snatch_system = 'curl';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>File Snatcher <?php echo $version; ?> - &copy; http://noveis.net</title>
</head>
<body>

<div id="main">
<?php
$submit = $_POST['submit'];
if ($submit)
{
	if (isset($password))
	{
		if ($_POST['password'] != $password)
		{
			die('<p><strong>Password incorrect!</strong></p>');
			$error = true;
		}
	}
	
	if (!$defaultDest)
	{
		$defaultDest = 'snatched';
	}
	
	if (!file_exists($defaultDest))
	{
		mkdir($defaultDest);
	}
	
	$sizelimit = $sizelimit * 1024;
	
	$file = $_POST['file'];
	
	$uploadfile = explode('/', $file);
	$filename = array_pop($uploadfile);
	
	$newfilename = $_POST['new'];
	
	if (!$newfilename)
	{
		$newfilename = $filename;
	}
	
	if (!isset($file))
	{
		echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>';
		$error = true;
	}
	
	if (!isset($newfilename))
	{
		echo '<p><strong>Please enter a new file name!</strong></p>';
		$error = true;
	}
	
	if ($error == false)
	{
		$dest = $defaultDest;
		$ds = array($dest, '/', $newfilename);
		$ds = implode('', $ds);
		$newname_count = 0;
		if (file_exists($ds))
		{
			echo '<p><strong>File already exists!</strong></p>';
			$newname_count++;
			$newfile = array($newname_count, $newfilename);
			$newfile = implode('~', $newfile);
			$newfile_ds = array($dest, '/', $newfile);
			$newfile_ds = implode('', $newfile_ds);
			while($renamed == false)
			{
				if (file_exists($newfile_ds))
				{
					$newname_count++;
					$newfile = array($newname_count, $newfilename);
					$newfile = implode('~', $newfile);
					$newfile_ds = array($dest, '/', $newfile);
					$newfile_ds = implode('', $newfile_ds);
				}
				else
				{
					$renamed = true;
				}
			}
			$newfilename = $newfile;
			$ds = $newfile_ds;
			echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>';
		}
		echo '<p><strong>Copying...</strong></p>';
		if ($snatch_system == 'curl')
		{
			$ch = curl_init($file);
			$fp = fopen($ds, 'w');
			curl_setopt($ch, CURLOPT_FILE, $fp);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_exec($ch);
			$curl_info =  curl_getinfo($ch);
			curl_close($ch);
			fclose($fp);
		}
		else
		{
			if (!copy($file, $ds))
			{
				echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
				$copy_fail = true;
			}
		}
		
		if ($copy_fail == false)
		{
			if ($sizelimit > 0 && filesize($ds) > $sizelimit)
			{
				echo '<p><strong>File is too large.</strong>';
				unlink($ds);
			}
			else
			{
				echo '<p><strong>Copy successful!</strong></p>';
				echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
				if ($snatch_system == 'curl')
				{
					$size_dl = round($curl_info['size_download']/1024, 2);
					$speed_dl = round($curl_info['speed_download']/1024, 2);
					echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
				}
			}
		}
	}
}

$self = $_SERVER['PHP_SELF'];
echo '<form method="POST" action="'.$self.'">';
echo '<fieldset><legend>File Snatcher</legend>';
echo '<label for="file">Full path to file to copy</label>';
echo '<p>Example: http://foobar.com/image.png</p>';
echo '<input type="text" name="file" id="file" size="45" value="">';
echo '<label for="new">New file name (Optional)</label><br />';
echo '<p>Example: image.png</p>';
echo '<input type="text" name="new" id="new" size="45" value="">';
if (isset($password))
{
	echo '<label for="password">Password</label>';
	echo '<input type="password" name="password" id="password" size="45" value=""><br />';
}
echo '<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>';
echo '</fieldset></form>';
?>
</div>
</body>
</html>

Please help me guys. Thanks in advance

Here is code for index.php.
check it, hope it is what you want.

<?php
//File Snatcher 2.7
define('_ALLOWINCLUDE',0);
include 'setting.php';
$version = '2.7';
//////////////////////////////////////////////
//Do Not Change Below Here////////////////////
//////////////////////////////////////////////
if (function_exists('curl_init'))
{
	$snatch_system = 'curl';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>File Snatcher <?php echo $version; ?> - &copy; http://noveis.net</title>
</head>
<body>

<div id="main">
<?php
$submit = $_POST['submit'];
if ($submit)
{
	if (isset($password))
	{
		if ($_POST['password'] != $password)
		{
			die('<p><strong>Password incorrect!</strong></p>');
			$error = true;
		}
	}
	
	if (!$defaultDest)
	{
		$defaultDest = 'snatched';
	}
	
	if (!file_exists($defaultDest))
	{
		mkdir($defaultDest);
	}
	
	$sizelimit = $sizelimit * 1024;
	
	$files = $_POST['file'];
	$news = $_POST['new'];
	
	for($i=0;$i<count($files);$i++)
	{
	
	$file = $files[$i];
	$uploadfile = explode('/', $file);
	$filename = array_pop($uploadfile);
	
	$newfilename = $news[$i];
	
	if (!$newfilename)
	{
		$newfilename = $filename;
	}
	
	if (!isset($file))
	{
		echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>';
		$error = true;
	}
	
	if (!isset($newfilename))
	{
		echo '<p><strong>Please enter a new file name!</strong></p>';
		$error = true;
	}
	
	if ($error == false)
	{
		$dest = $defaultDest;
		$ds = array($dest, '/', $newfilename);
		$ds = implode('', $ds);
		$newname_count = 0;
		if (file_exists($ds))
		{
			echo '<p><strong>File already exists!</strong></p>';
			$newname_count++;
			$newfile = array($newname_count, $newfilename);
			$newfile = implode('~', $newfile);
			$newfile_ds = array($dest, '/', $newfile);
			$newfile_ds = implode('', $newfile_ds);
			while($renamed == false)
			{
				if (file_exists($newfile_ds))
				{
					$newname_count++;
					$newfile = array($newname_count, $newfilename);
					$newfile = implode('~', $newfile);
					$newfile_ds = array($dest, '/', $newfile);
					$newfile_ds = implode('', $newfile_ds);
				}
				else
				{
					$renamed = true;
				}
			}
			$newfilename = $newfile;
			$ds = $newfile_ds;
			echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>';
		}
		echo '<p><strong>Copying...</strong></p>';
		if ($snatch_system == 'curl')
		{
			$ch = curl_init($file);
			$fp = fopen($ds, 'w');
			curl_setopt($ch, CURLOPT_FILE, $fp);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_exec($ch);
			$curl_info =  curl_getinfo($ch);
			curl_close($ch);
			fclose($fp);
		}
		else
		{
			if (!copy($file, $ds))
			{
				echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
				$copy_fail = true;
			}
		}
		
		if ($copy_fail == false)
		{
			if ($sizelimit > 0 && filesize($ds) > $sizelimit)
			{
				echo '<p><strong>File is too large.</strong>';
				unlink($ds);
			}
			else
			{
				echo '<p><strong>Copy successful!</strong></p>';
				echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
				if ($snatch_system == 'curl')
				{
					$size_dl = round($curl_info['size_download']/1024, 2);
					$speed_dl = round($curl_info['speed_download']/1024, 2);
					echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
				}
			}
		}
	}
	
	}
}

$self = $_SERVER['PHP_SELF'];
?>

<fieldset><legend>File Snatcher</legend>
<label for="file">Full path to file to copy</label>
<p>Example: http://foobar.com/image.png</p>
<?
	$repeat = (isset($_REQUEST['repeat']))?($_REQUEST['repeat']):(1);
?>
<form method="POST" action="<?=$self?>">
<input type="text" name="repeat"  size="10" value="<?=$repeat;?>">
<input name="Repeat" value="Repeat" type="submit">
</form>

<form method="POST" action="<?=$self?>">
<? for($i=0;$i<$repeat;$i++){?>
<br>File<?=($i+1)?> : <input type="text" name="file[]"  size="45" value="">
<input type="text" name="new[]" size="45" value="">
<? } ?>

<label for="new">New file name (Optional)</label><br />
<p>Example: image.png</p>

<? if (isset($password)){ ?>

	<label for="password">Password</label>
	<input type="password" name="password" id="password" size="45" value=""><br />
<? } ?>
<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>
</form>
</fieldset>

</div>
</body>
</html>
commented: one word... vibhadevit is awesome +1

Dude you helped me a lot. Really awesome. Thanks for your help.

Here is code for index.php.
check it, hope it is what you want.

<?php
//File Snatcher 2.7
define('_ALLOWINCLUDE',0);
include 'setting.php';
$version = '2.7';
//////////////////////////////////////////////
//Do Not Change Below Here////////////////////
//////////////////////////////////////////////
if (function_exists('curl_init'))
{
	$snatch_system = 'curl';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>File Snatcher <?php echo $version; ?> - &copy; http://noveis.net</title>
</head>
<body>

<div id="main">
<?php
$submit = $_POST['submit'];
if ($submit)
{
	if (isset($password))
	{
		if ($_POST['password'] != $password)
		{
			die('<p><strong>Password incorrect!</strong></p>');
			$error = true;
		}
	}
	
	if (!$defaultDest)
	{
		$defaultDest = 'snatched';
	}
	
	if (!file_exists($defaultDest))
	{
		mkdir($defaultDest);
	}
	
	$sizelimit = $sizelimit * 1024;
	
	$files = $_POST['file'];
	$news = $_POST['new'];
	
	for($i=0;$i<count($files);$i++)
	{
	
	$file = $files[$i];
	$uploadfile = explode('/', $file);
	$filename = array_pop($uploadfile);
	
	$newfilename = $news[$i];
	
	if (!$newfilename)
	{
		$newfilename = $filename;
	}
	
	if (!isset($file))
	{
		echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>';
		$error = true;
	}
	
	if (!isset($newfilename))
	{
		echo '<p><strong>Please enter a new file name!</strong></p>';
		$error = true;
	}
	
	if ($error == false)
	{
		$dest = $defaultDest;
		$ds = array($dest, '/', $newfilename);
		$ds = implode('', $ds);
		$newname_count = 0;
		if (file_exists($ds))
		{
			echo '<p><strong>File already exists!</strong></p>';
			$newname_count++;
			$newfile = array($newname_count, $newfilename);
			$newfile = implode('~', $newfile);
			$newfile_ds = array($dest, '/', $newfile);
			$newfile_ds = implode('', $newfile_ds);
			while($renamed == false)
			{
				if (file_exists($newfile_ds))
				{
					$newname_count++;
					$newfile = array($newname_count, $newfilename);
					$newfile = implode('~', $newfile);
					$newfile_ds = array($dest, '/', $newfile);
					$newfile_ds = implode('', $newfile_ds);
				}
				else
				{
					$renamed = true;
				}
			}
			$newfilename = $newfile;
			$ds = $newfile_ds;
			echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>';
		}
		echo '<p><strong>Copying...</strong></p>';
		if ($snatch_system == 'curl')
		{
			$ch = curl_init($file);
			$fp = fopen($ds, 'w');
			curl_setopt($ch, CURLOPT_FILE, $fp);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_exec($ch);
			$curl_info =  curl_getinfo($ch);
			curl_close($ch);
			fclose($fp);
		}
		else
		{
			if (!copy($file, $ds))
			{
				echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
				$copy_fail = true;
			}
		}
		
		if ($copy_fail == false)
		{
			if ($sizelimit > 0 && filesize($ds) > $sizelimit)
			{
				echo '<p><strong>File is too large.</strong>';
				unlink($ds);
			}
			else
			{
				echo '<p><strong>Copy successful!</strong></p>';
				echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
				if ($snatch_system == 'curl')
				{
					$size_dl = round($curl_info['size_download']/1024, 2);
					$speed_dl = round($curl_info['speed_download']/1024, 2);
					echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
				}
			}
		}
	}
	
	}
}

$self = $_SERVER['PHP_SELF'];
?>

<fieldset><legend>File Snatcher</legend>
<label for="file">Full path to file to copy</label>
<p>Example: http://foobar.com/image.png</p>
<?
	$repeat = (isset($_REQUEST['repeat']))?($_REQUEST['repeat']):(1);
?>
<form method="POST" action="<?=$self?>">
<input type="text" name="repeat"  size="10" value="<?=$repeat;?>">
<input name="Repeat" value="Repeat" type="submit">
</form>

<form method="POST" action="<?=$self?>">
<? for($i=0;$i<$repeat;$i++){?>
<br>File<?=($i+1)?> : <input type="text" name="file[]"  size="45" value="">
<input type="text" name="new[]" size="45" value="">
<? } ?>

<label for="new">New file name (Optional)</label><br />
<p>Example: image.png</p>

<? if (isset($password)){ ?>

	<label for="password">Password</label>
	<input type="password" name="password" id="password" size="45" value=""><br />
<? } ?>
<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>
</form>
</fieldset>

</div>
</body>
</html>

Here is you code(with example form filled) to insert all URL at a time:

<?php
//File Snatcher 2.7
define('_ALLOWINCLUDE',0);
include 'setting.php';
$version = '2.7';
//////////////////////////////////////////////
//Do Not Change Below Here////////////////////
//////////////////////////////////////////////
if (function_exists('curl_init'))
{
	$snatch_system = 'curl';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>File Snatcher <?php echo $version; ?> - &copy; http://noveis.net</title>
</head>
<body>

<div id="main">
<?php
$submit = $_POST['submit'];
if ($submit)
{
	if (isset($password))
	{
		if ($_POST['password'] != $password)
		{
			die('<p><strong>Password incorrect!</strong></p>');
			$error = true;
		}
	}
	
	if (!$defaultDest)
	{
		$defaultDest = 'snatched';
	}
	
	if (!file_exists($defaultDest))
	{
		mkdir($defaultDest);
	}
	
	$sizelimit = $sizelimit * 1024;
	
	$files = $_POST['file'];
	$news = $_POST['new'];
	$allfiles = $_POST['allfiles'];
	$separateby = $_POST['separateby'];
	if($allfiles != "")
	{
		$files = explode($separateby,$allfiles);
	}
	for($i=0;$i<count($files);$i++)
	{
		
		$file = trim($files[$i]);
		$uploadfile = explode('/', $file);
		$filename = array_pop($uploadfile);
		
		$newfilename = $news[$i];
		
		if (!$newfilename)
		{
			$newfilename = $filename;
		}
		
		if (!isset($file))
		{
			echo '<p><strong>Please enter a URL to retrieve file from!</strong></p>';
			$error = true;
		}
		
		if (!isset($newfilename))
		{
			echo '<p><strong>Please enter a new file name!</strong></p>';
			$error = true;
		}
		
		if ($error == false)
		{
			$dest = $defaultDest;
			$ds = array($dest, '/', $newfilename);
			$ds = implode('', $ds);
			$newname_count = 0;
			if (file_exists($ds))
			{
				echo '<p><strong>File already exists!</strong></p>';
				$newname_count++;
				$newfile = array($newname_count, $newfilename);
				$newfile = implode('~', $newfile);
				$newfile_ds = array($dest, '/', $newfile);
				$newfile_ds = implode('', $newfile_ds);
				while($renamed == false)
				{
					if (file_exists($newfile_ds))
					{
						$newname_count++;
						$newfile = array($newname_count, $newfilename);
						$newfile = implode('~', $newfile);
						$newfile_ds = array($dest, '/', $newfile);
						$newfile_ds = implode('', $newfile_ds);
					}
					else
					{
						$renamed = true;
					}
				}
				$newfilename = $newfile;
				$ds = $newfile_ds;
				echo '<p>New file name is <strong>'.$newfile.'</strong>.</p>';
			}
			echo '<p><strong>Copying...</strong></p>';
			if ($snatch_system == 'curl')
			{
				$ch = curl_init($file);
				$fp = fopen($ds, 'w');
				curl_setopt($ch, CURLOPT_FILE, $fp);
				curl_setopt($ch, CURLOPT_HEADER, 0);
				curl_exec($ch);
				$curl_info =  curl_getinfo($ch);
				curl_close($ch);
				fclose($fp);
			}
			else
			{
				if (!copy($file, $ds))
				{
					echo '<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
					$copy_fail = true;
				}
			}
			
			if ($copy_fail == false)
			{
				if ($sizelimit > 0 && filesize($ds) > $sizelimit)
				{
					echo '<p><strong>File is too large.</strong>';
					unlink($ds);
				}
				else
				{
					echo '<p><strong>Copy successful!</strong></p>';
					echo '<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
					if ($snatch_system == 'curl')
					{
						$size_dl = round($curl_info['size_download']/1024, 2);
						$speed_dl = round($curl_info['speed_download']/1024, 2);
						echo '<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
					}
				}
			}
		}
		
	}
}

$self = $_SERVER['PHP_SELF'];
?>

<fieldset><legend>File Snatcher</legend>
<label for="file">Full path to file to copy</label>
<p>Example: http://foobar.com/image.png</p>
<?
	$repeat = (isset($_REQUEST['repeat']))?($_REQUEST['repeat']):(1);
?>
<form method="POST" action="<?=$self?>">
<input type="text" name="repeat"  size="10" value="<?=$repeat;?>">
<input name="Repeat" value="Repeat" type="submit">
</form>

<form method="POST" action="<?=$self?>">
<? for($i=0;$i<$repeat;$i++){?>
<br>File<?=($i+1)?> : <input type="text" name="file[]"  size="45" value="">
<!--<input type="text" name="new[]" size="45" value="">-->
<? } ?>

<label for="new">New file name (Optional)</label><br />
<br>OR<br><br>
<textarea name="allfiles" cols="100" rows="10">http://www.daniweb.com/rxrimages/feeds_rss.gif##http://www.daniweb.com/rxrimages/feeds_twitter.gif##http://www.daniweb.com/rxrimages/feeds_facebook.gif</textarea>
Separate URL by:
<input type="text" value="##" name="separateby"  size="5" value="<?=$separateby;?>">

<p>Example: image.png</p>

<? if (isset($password)){ ?>

	<label for="password">Password</label>
	<input type="password" name="password" id="password" size="45" value=""><br />
<? } ?>
<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>
</form>
</fieldset>

</div>
</body>
</html>
commented: Thanks buddy +1

vibhaJ can you add some additional function like change dir please i use this script but i want to change dir for each file through ftp can you make it easy through this scrip thanks in advance and sorry for my very bad english

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.