Page 1 of 2

Downloading files

Posted: Wed Mar 01, 2006 9:42 pm
by xcom923
OK, I'm having to Use URLs from a file and make my server download these files. For some reason it won't do it, but when I copy and paste the URLs they work in my browser. here is an example

torrent link to copyrighted content removed

do you think the fread() needs me to encode the URL in some way? I'm also using file_get_contents as a backup and still nothing.

Posted: Wed Mar 01, 2006 10:04 pm
by John Cartwright
it would help if you posted some code first

Posted: Thu Mar 02, 2006 5:57 am
by Maugrim_The_Reaper
Just to be certain - you're aware this is a torrent file? Requires a torrent client to download the file it represents. Downloading the url will usually net you a 20KB or so file used by a torrent client.

Posted: Thu Mar 02, 2006 6:00 am
by xcom923
Jcart | Please use

Code: Select all

and

Code: Select all

tags when posting code[/color]

Code: Select all

//downloading functions
function getFileContents($fullPath){
	$path = $fullPath;
	if( doesFileExist($path)){
		$return = file_get_contents($path); 
		return $return;
	}
}

function downloadFile($URL,$bytes='128'){
	if ( $fp = fopen($httpurl, "r") ){
		$stream = "";
		if ($fp) {
			while( !feof( $fp ) ) {
				$stream .= fread($fp, $bytes);
			}
		}
		fclose($fp);
	}else{
		$stream = NULL;
	}
	return $stream;
}
///end library

$Contents = downloadFile($data['URL']);
if($Contents == NULL){
	$Contents = getFileContents($data['URL']);
}
if($Contents == NULL){
	$Contents = getFileContents(rawurldecode($data['URL']));
}
if($Contents != NULL){
	write_file($Temp_path,$Contents);
}
Jcart | Please use

Code: Select all

and

Code: Select all

tags when posting code[/color]

Posted: Thu Mar 02, 2006 1:25 pm
by xcom923
Maugrim_The_Reaper wrote:Just to be certain - you're aware this is a torrent file? Requires a torrent client to download the file it represents. Downloading the url will usually net you a 20KB or so file used by a torrent client.
....yeah I do know that. that's not the point. I'm just trying to download the file itself. to the server, I'm mainly wondering if it needs to be encoded for URL, IE spaces must be %20 or something to that effect.

Posted: Fri Mar 03, 2006 6:45 am
by Jenk
I'm not quite sure what you are after here, so this Q is just for clarification:

Are you trying to serve the file to clients as a download?

If so - modify the header() info to 'Disposition: Attachment' along with the meta-type and file size.

Posted: Sat Mar 04, 2006 7:28 am
by xcom923
no, when I say I'm trying to 'download' the file I mean I am trying to download it to the server not so someone else can download it I want to use the file myself

Posted: Sat Mar 04, 2006 9:10 am
by timvw
If i'm not mistaken there is an option to indicate which chunk of a document/page you really want to recieve... That way you could pause/resume downloads (if the server is capable of this functionality).. Much nicer than having to download the complete file again if your connection dies after 500mb of a 600mb iso...

Posted: Sat Mar 04, 2006 9:27 am
by Chris Corbyn
OK I'm still not certain what you want.

Let's say you have a torrent file called myvideo.iso.torrent

Do you want to:

a) Download myvideo.iso.torrent
b) Download myvideo.iso

?

Posted: Sat Mar 04, 2006 11:25 am
by Jenk
xcom923 wrote:no, when I say I'm trying to 'download' the file I mean I am trying to download it to the server not so someone else can download it I want to use the file myself
You mean upload.

Posted: Sat Mar 04, 2006 5:35 pm
by josh

Code: Select all

$file = 'http://example.com/test.torrent';
$data = file_get_contents($file);
$h=fopen('downloads/'.basename($file),'w');
fwrite($h,$data);
fclose($h);
?

Posted: Fri Mar 10, 2006 2:18 pm
by xcom923
don't worry I got it.

but the clerify I am talking about downloading. Although it's not downloading from to my computer it's downloading from a host to my server which is still "downloading" also I just wanted the torrent file not the file it points to.

in the end my system has been completed with version 1. Pretty much it was a system to add torrents to itself on it's own. it cam out pretty well (http://www.anivision.us)

Posted: Fri Mar 10, 2006 2:37 pm
by Chris Corbyn
Hmm... I wonder just how easy it would be to write a bit torrent client in PHP. I know the official one is written in python/ncurses.

Posted: Fri Mar 10, 2006 2:50 pm
by R4000
its been done!
i dont want to direct linky.

but its called "TorrentFlux"

i used to have it on my server, the day after i stopped paying. I installed it.

Got about 2 months of free bandwidth :P

Posted: Sun Mar 12, 2006 3:36 pm
by Ambush Commander
You could always interface to an engine in a different language... (via shell or php extension)