Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-27-2007, 08:39 AM Help With Script
Junior Talker

Posts: 3
Name: Nimish
Trades: 0
here is my script
i dont have much knowledge bout php so can u plz edit and give me proper script using which i can upload files on my server directly through url

index.php
Code:
<?php
define('_ALLOWINCLUDE',0);
include 'settings.php';
$version = '2.8 Beta 3';

//////////////////////////////////////////////
//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>
<title>File Snatcher <?php echo $version; ?> - &copy; http://freaks.uk.to</title>
<style type="text/css">
iframe {
	border:none;
	width:600px;
	height:100px;
	overflow:hidden;
}

div.p3news_bar {
	margin-top:2px;
	height:16px;
	background-color:#ab4a37;
	border-bottom:1px solid #5f1000;
	border-right:1px solid #af1d00;
	color:#ffffff;
	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 .'&amp;fs='.$file_size.'&amp;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.'&amp;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://foobar.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>



settings.php
Code:
<?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 = '/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://frendz.12gbfree.com/files';


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

?>
nimish01 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-29-2007, 07:39 AM Re: Help With Script
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
don't want to be mean but :
a. if you don't have any knowledge about php and want someone to make the whole script ... hire a coder ( post in the proper forum on this website )
b. if you want to learn and need help fixing this script, tell us the problem with it, what is not working
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 12-21-2007, 07:23 AM Re: Help With Script
Junior Talker

Posts: 3
Name: Nimish
Trades: 0
when i use this script to download it starts processing some gibrish language on the index page and it keeps writing gibrish till the file size gets completely downloaded then it says copying completed but the file doesnt get copied
plz help me
nimish01 is offline
Reply With Quote
View Public Profile
 
Old 12-21-2007, 07:28 AM Re: Help With Script
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
if you want help you need to post only the part of code with problems, i for one don't have time to analyze the whole code, at least not for free
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 12-21-2007, 08:01 AM Re: Help With Script
Junior Talker

Posts: 3
Name: Nimish
Trades: 0
when i use this script to download it starts processing some gibrish language on the index page and it keeps writing gibrish till the file size gets completely downloaded then it says copying completed but the file doesnt get copied
plz help me
nimish01 is offline
Reply With Quote
View Public Profile
 
Old 12-21-2007, 11:21 AM Re: Help With Script
Mattmaul1992's Avatar
Ultra Talker

Posts: 486
Name: Matt
Trades: -1
Seriously, messy code.. Learn what you're doing bud.
__________________
PHP Code:
$talkupation++; 

Please login or register to view this content. Registration is FREE
- Free IPB forum hosting (releasing today!!!), no ads, free modifications
Mattmaul1992 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help With Script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16717 seconds with 12 queries