ViNeeT_4u
04-16-2008, 12:05 PM
i gt a url upload script but when i copy something it didnt get copied.
here the script
index.php
<?php
define('_ALLOWINCLUDE',0);
include 'settings.php';
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>
<title>UPLOAD ARENA<?php echo $version; ?> - © http://xyz.com</title>
<style type="text/css">
iframe {
border:none;
width:600px;
height:100px;
overflow:hidden;
}
div.p3news_bar {
margin-top:2px;
height:16px;
background-color:#1E90FF;
border-bottom:1px solid #5f1000;
border-right:1px solid #af1d00;
color:#228B22;
text-align:right;
font-weight:bold;
font-size:12px;
}
</style>
</head>
<body>
<div id="main">
<?php
$submit = $_POST['submit'];
$file_size = $_GET['fs'];
$ds = $_GET['ds'];
if ($_GET['fs'] == true)
{
$ds_fs = filesize($ds);
$progress = round(($ds_fs/$file_size)*100, 2);
if($progress >= 100)
{
$done = 1;
}
else
{
$done = 0;
}
if($_GET['done'] == 0)
{
echo '<meta http-equiv="refresh" content="'. $refresh_time .';index.php?&done='. $done .'&fs='.$file_size.'&ds='.$ds.'">';
}
echo '<div class="p3news_bar" style="width:'. $progress .'%;">'. $progress .'% copied</div>';
echo '<p>Copied '. round($ds_fs/1024, 2) .' of '. round($file_size/1024, 2) .'KB</p>';
}
elseif ($submit == true)
{
if (isset($password))
{
if ($_POST['password'] != $password)
{
die('<p><strong>Password incorrect!</strong></p>');
$error = true;
}
}
if (!file_exists($defaultDest))
{
mkdir($defaultDest);
}
chdir($defaultDest);
$sizelimit_kb = $sizelimit;
$sizelimit = $sizelimit * 1024;
$file = rawurldecode($_POST['file']);
$uploadfile = explode('/', $file);
$filename = array_pop($uploadfile);
$newfilename = $_POST['new'];
if(strstr($newfilename, '/'))
{
$new_path = explode('/', $newfilename);
array_pop($new_path);
$new_path = implode('/', $new_path);
if(!file_exists($new_path))
{
mkdir($new_path);
echo '<p>Making directory "'. $new_path .'"</p>';
}
}
$newfilename = str_replace('*', $filename, $newfilename);
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>';
//Dev Add - next 1 line
$new_name_needed = true;
$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')
{
// Start Remote File Size //
ob_start();
$chF = curl_init($file);
curl_setopt($chF, CURLOPT_HEADER, 1);
curl_setopt($chF, CURLOPT_NOBODY, 1);
$ok = curl_exec($chF);
curl_close($chF);
$head = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex, $head, $matches);
if($matches[1] > 0)
{
if (isset($matches))
{
$file_size = $matches[1];
$file_size_kb = round($file_size/1024, 2);
echo '<p>Size of file to be copied: '.$file_size_kb.'KB.</p>';
}
else
{
$no_filesize = true;
unset($file_size);
}
}
else
{
echo '<p>Could not get file size.</p>';
}
if($file_size > $sizelimit && $sizelimit > 0)
{
echo '<p>File size is too large.<br />Max file size is '.$sizelimit_kb.'KB.</p>';
$copy_fail = true;
}
if($copy_file == false && $file_size > 0)
{
echo '<iframe name="progress"
src="index.php?fs='.$file_size.'&ds='.$ds.'">
</iframe>';
$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.';
}
}
}
}
}
if ($_GET['fs'] == false)
{
$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://xyz.com/image.png</p>';
echo '<p><input type="text" name="file" id="file" size="45" value=""></p>';
echo '<label for="new">New file name (Optional)</label><br />';
echo '<p>Example: image.png. Or you can specify a different path in relation to the default path, and you can use an asterix (*) to use the orginal file name. Example: new_folder/*</p>';
echo '<p><input type="text" name="new" id="new" size="45" value=""></p>';
if (isset($password))
{
echo '<label for="password">Password</label>';
echo '<p><input type="password" name="password" id="password" size="45" value=""></p>';
}
echo '<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>';
echo '</fieldset></form>';
}
?>
</div>
</body>
</html>
setting.php
<?php
defined('_ALLOWINCLUDE') or die();
// Default destination to copy files too NO TRAILING SLASH!!
// If it is complete path, file be copied there eg: /home/public_html/FOLDER (Linux) C:\htdocs\FOLDER (Windows)
// If it is just a folder it will be copied to the folder the script is in, but in the folder eg: /SnatcherFolder/FOLDER
$defaultDest = '/home/examplene/public_html/files';
// 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 = 'password';
// Operating System your SERVER Uses
//1 for Linux. 2 for Windows.
//I'm not sure but I think most Operating Systems other then Windows will use 1.
$os = '1';
// URL to location of snatched files WITH OUT TRAILING SLASH
$URLDest = 'http://xyz.com/files';
// Put a limit for file size in kilobytes (1024KB is 1MB)
// For unlimited put 0
// Example $sizelimit = 25;
$sizelimit = 0;
?>
kindly help me,i 'll be very thanful to you
here the script
index.php
<?php
define('_ALLOWINCLUDE',0);
include 'settings.php';
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>
<title>UPLOAD ARENA<?php echo $version; ?> - © http://xyz.com</title>
<style type="text/css">
iframe {
border:none;
width:600px;
height:100px;
overflow:hidden;
}
div.p3news_bar {
margin-top:2px;
height:16px;
background-color:#1E90FF;
border-bottom:1px solid #5f1000;
border-right:1px solid #af1d00;
color:#228B22;
text-align:right;
font-weight:bold;
font-size:12px;
}
</style>
</head>
<body>
<div id="main">
<?php
$submit = $_POST['submit'];
$file_size = $_GET['fs'];
$ds = $_GET['ds'];
if ($_GET['fs'] == true)
{
$ds_fs = filesize($ds);
$progress = round(($ds_fs/$file_size)*100, 2);
if($progress >= 100)
{
$done = 1;
}
else
{
$done = 0;
}
if($_GET['done'] == 0)
{
echo '<meta http-equiv="refresh" content="'. $refresh_time .';index.php?&done='. $done .'&fs='.$file_size.'&ds='.$ds.'">';
}
echo '<div class="p3news_bar" style="width:'. $progress .'%;">'. $progress .'% copied</div>';
echo '<p>Copied '. round($ds_fs/1024, 2) .' of '. round($file_size/1024, 2) .'KB</p>';
}
elseif ($submit == true)
{
if (isset($password))
{
if ($_POST['password'] != $password)
{
die('<p><strong>Password incorrect!</strong></p>');
$error = true;
}
}
if (!file_exists($defaultDest))
{
mkdir($defaultDest);
}
chdir($defaultDest);
$sizelimit_kb = $sizelimit;
$sizelimit = $sizelimit * 1024;
$file = rawurldecode($_POST['file']);
$uploadfile = explode('/', $file);
$filename = array_pop($uploadfile);
$newfilename = $_POST['new'];
if(strstr($newfilename, '/'))
{
$new_path = explode('/', $newfilename);
array_pop($new_path);
$new_path = implode('/', $new_path);
if(!file_exists($new_path))
{
mkdir($new_path);
echo '<p>Making directory "'. $new_path .'"</p>';
}
}
$newfilename = str_replace('*', $filename, $newfilename);
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>';
//Dev Add - next 1 line
$new_name_needed = true;
$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')
{
// Start Remote File Size //
ob_start();
$chF = curl_init($file);
curl_setopt($chF, CURLOPT_HEADER, 1);
curl_setopt($chF, CURLOPT_NOBODY, 1);
$ok = curl_exec($chF);
curl_close($chF);
$head = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex, $head, $matches);
if($matches[1] > 0)
{
if (isset($matches))
{
$file_size = $matches[1];
$file_size_kb = round($file_size/1024, 2);
echo '<p>Size of file to be copied: '.$file_size_kb.'KB.</p>';
}
else
{
$no_filesize = true;
unset($file_size);
}
}
else
{
echo '<p>Could not get file size.</p>';
}
if($file_size > $sizelimit && $sizelimit > 0)
{
echo '<p>File size is too large.<br />Max file size is '.$sizelimit_kb.'KB.</p>';
$copy_fail = true;
}
if($copy_file == false && $file_size > 0)
{
echo '<iframe name="progress"
src="index.php?fs='.$file_size.'&ds='.$ds.'">
</iframe>';
$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.';
}
}
}
}
}
if ($_GET['fs'] == false)
{
$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://xyz.com/image.png</p>';
echo '<p><input type="text" name="file" id="file" size="45" value=""></p>';
echo '<label for="new">New file name (Optional)</label><br />';
echo '<p>Example: image.png. Or you can specify a different path in relation to the default path, and you can use an asterix (*) to use the orginal file name. Example: new_folder/*</p>';
echo '<p><input type="text" name="new" id="new" size="45" value=""></p>';
if (isset($password))
{
echo '<label for="password">Password</label>';
echo '<p><input type="password" name="password" id="password" size="45" value=""></p>';
}
echo '<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>';
echo '</fieldset></form>';
}
?>
</div>
</body>
</html>
setting.php
<?php
defined('_ALLOWINCLUDE') or die();
// Default destination to copy files too NO TRAILING SLASH!!
// If it is complete path, file be copied there eg: /home/public_html/FOLDER (Linux) C:\htdocs\FOLDER (Windows)
// If it is just a folder it will be copied to the folder the script is in, but in the folder eg: /SnatcherFolder/FOLDER
$defaultDest = '/home/examplene/public_html/files';
// 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 = 'password';
// Operating System your SERVER Uses
//1 for Linux. 2 for Windows.
//I'm not sure but I think most Operating Systems other then Windows will use 1.
$os = '1';
// URL to location of snatched files WITH OUT TRAILING SLASH
$URLDest = 'http://xyz.com/files';
// Put a limit for file size in kilobytes (1024KB is 1MB)
// For unlimited put 0
// Example $sizelimit = 25;
$sizelimit = 0;
?>
kindly help me,i 'll be very thanful to you