Downloading files

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

Downloading files

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

it would help if you posted some code first
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

Post 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]
xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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

?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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);
?
xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

Post 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)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You could always interface to an engine in a different language... (via shell or php extension)
Post Reply