Downloading Quesiton

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Downloading Quesiton

Post by Sphenn »

Hey again guys.

Sorry for all the questions, but I have another one.

I'm trying to figure out how to download a file (or tarball, thanks Feyd) from a website using PHP, but it's not working.

Could anyone give me some pointers?

Thanks

Sphenn
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

given the proper url file_get_contents() can often do the job. The output from the request will be in the return data.
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Thanks Feyd, this gave me an idea that works somewhat. However, this causes a file to be created with an ".out" extension appended to the filename specified. Do you know if there's any way to remove this without renaming the file itself (which is doable, I just don't want to do it if I don't have to)

Thanks for all your help :D

Sphenn
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how are you using it? (post your code, remember

Code: Select all

tags! )
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

I have this right now:

Code: Select all

<?php
$CVS = file_get_contents('http://cvs.sourceforge.net/cvstarballs/simplebb-cvsroot.tar.bz2');
$time = time();
file_put_contents('asdf-' . $time . 'zip', $CVS);
?>
This gives me a file called:

asdf-101020030.zip.out

If I remove the .out extension, I have another zip file which then has the files that I want. Do you know of a way to get rid of the extension and the second zip package?

Thanks for your time

Sphenn
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

running that locally gives me asdf-101020030zip

it needs to be named asdf-101020030.tar.bz2 or the file won't be read by most programs correctly..

Code: Select all

<?php
$CVS = file_get_contents('http://cvs.sourceforge.net/cvstarballs/simplebb-cvsroot.tar.bz2');
$time = time();
file_put_contents('asdf-' . $time . '.tar.bz2', $CVS);
?>

What do you mean by "second zip package" ?
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Oops, forgot the "." in the ext.

Code: Select all

<?php
$CVS = file_get_contents('http://cvs.sourceforge.net/cvstarballs/simplebb-cvsroot.tar.bz2');
$time = time();
file_put_contents('asdf-' . $time . '.zip', $CVS);
?>
When I run this code, I get a file named: "asdf -1135253082.zip". If I extract this, I get a file named: "asdf-1135253082.zip.out". If I remove the ".out" extension, I get a zip archive which contains the files that I want to have. I don't know why this is happening.

Thanks for all of your help

Sphenn
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Ok, this is weird. I wrote the code out again, and now it's working perfectly.. 8O I don't know if anything changed, but it's working fine now.

Thanks for spending your time helping me Feyd.

Thanks again

Sphenn
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's because the file isn't a zip archive.. it's a tarball inside a bzip2 archive. bzip2 archives use their own filename to derive the name of the package they contain (to save some space), therefore the file must be named .tar.bz2 to correctly unpack..
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Ok, thanks.

Actually, there is one more thing. When I unpacked the file, each file had a ",v" appended to it. Do you think this would be related to the bz2 part?

And once again, thank you

Sphenn
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it appears to be apart of the version control, such as the original file.. looking at the dates of ones with and without the ,v would make sense.. I don't remember how CVS stores the files internally.. too used to SVN and VSS :lol:
Sphenn
Forum Commoner
Posts: 48
Joined: Sun Jul 17, 2005 8:08 pm
Location: Winnipeg, MB

Post by Sphenn »

Hmm...it appears I'll have to figure out a way to get rid of it. I just hope I don't have to rename each file every time...

Oh well,

Thanks

Sphenn
Post Reply