Jump to content

Multi File Copier


Recommended Posts

Let's you copy multiple urls to any directory you select. Uses cURL:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Multi Curl Copier</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
 background: #ffffff;
 font-family: 'Trebuchet MS', Arial, sans-serif;
 color: #000060;
 font-size: 15px;
}

h1, h2, h3, h4, h5 {
 font-family: Georgia, 'Times New Roman', serif;
}

h1 {
 color: #000060;
 font-size: 24px;
 text-align: center;
}

table {
 margin-left: auto;
 margin-right: auto;
}

.tablmain {
 width: 600px;
 margin-left: auto;
 margin-right: auto;
 font-size: 14px;
}

.center {
 text-align: center;
}

select {
 width: 130px;
}

.note {
 font-size: 12px;
 text-align: center;
}

#urls {
 margin-left: 10px;
 text-align: left;
}

#folder {
 font-size: 19px;
 text-align: center;
}

.fail {
 color: #cc0000;
}

.success {
 color: #00ff00;
}

-->
</style>
</head>
<body>
<?php
# error_reporting(0);
if ( $_POST[files] )
{
$files = $_POST[files];
$Sdir = $_POST[sdir];

$array_1 = explode( "\n", $files);
# filter out obvious non-URL's & trim trailing spaces
foreach ($array_1 as $temp)
{
if ( preg_match("@^http@i", $temp) )
{ $array_2[] = trim($temp); }
}

echo "<br><br>\n";
echo "<div id=\"urls\">\n";
echo "<div id=\"folder\">Folder: $Sdir</div><br><br>\n";

foreach($array_2 as $urls)
{
# get hostname
$url_part1 = parse_url($urls);
$host = ($url_part1['host']);

# get extension name
$url_part2 = pathinfo($urls);
$new_name = ($url_part2['basename']);

# user agent, cookie file
$agent = $_SERVER[HTTP_USER_AGENT];
$cook_file = "cookie_file.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urls);
curl_setopt($ch, CURLOPT_REFERER, "http://$host");
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cook_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cook_file);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$bytes = curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD);
curl_close($ch);

# if connection good, write files
if($httpcode >= 200 && $httpcode < 303)
{

# fix file names
$new_name = rawurlencode($new_name);
$new_name = str_replace("%","_",$new_name);

# write files
file_put_contents("$Sdir/$new_name", $result);

# remove root from file name to display link
$Ldir = preg_replace("@$_SERVER[DOCUMENT_ROOT]@", "", $Sdir);

# display links
echo "<span class=\"success\">Saved:</span> $urls<br>As: <a href=\"http://$_SERVER[sERVER_NAME]$Ldir/$new_name\">http://$_SERVER[sERVER_NAME]$Ldir/$new_name</a><br>";
echo "You transfered $bytes bytes<br><br>";
}
else
{
echo "<span class=\"fail\">Failed:</span> $urls<br><br>";
}
}
# delete cookie file
if (file_exists($cook_file)) {
unlink($cook_file);
}
echo "</div>";
}
?>

<table class="tablmain" cellpadding="15" cellspacing="0" border="0">
<tr>
<td align="center">
<br>
<hr>
<h1>Multi Curl Copier</h1>
<hr>
<br>
<form action="" method="post">
<table align="center" cellpadding="0" cellspacing="2" border="0">
<tr>
<td align="center">
<span class="note">(Use your Return key to start each url on a new line.)</span><br>
<textarea name="files" cols="60" rows="10"><?php echo $_POST[files]; ?></textarea>
<br>
<select onchange=form.Sdir.value=this.value; name="Sdir" width="130">
<option value="">Directory</option>
<option value="<?=$_SERVER[DOCUMENT_ROOT];?>">Root</option>
<?php
$root = "$_SERVER[DOCUMENT_ROOT]";
$iterator = new RecursiveDirectoryIterator($root);
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $dir) 
{
if (is_dir($dir)) {

## remove document root ##
$dir = preg_replace("@$_SERVER[DOCUMENT_ROOT]/@", "", $dir);

$dirs[] = $dir;
}
}
## loop through files ##
asort($dirs);

foreach($dirs as $value)
{
echo "<option value=\"$root/$value\">$value</option>";
}
?>
</select>

<input type="submit" name="Submit" value="Copy Files">
</td>
</tr>
</table>
</form>
<br><br>
</body>
</html>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...