Page 1 of 1
Downloading Quesiton
Posted: Sat Nov 05, 2005 10:29 pm
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
Posted: Sat Nov 05, 2005 10:33 pm
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.
Posted: Sat Nov 05, 2005 10:40 pm
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
Sphenn
Posted: Sat Nov 05, 2005 10:43 pm
by feyd
how are you using it? (post your code, remember
Posted: Sat Nov 05, 2005 10:47 pm
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
Posted: Sat Nov 05, 2005 10:55 pm
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" ?
Posted: Sat Nov 05, 2005 10:59 pm
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
Posted: Sat Nov 05, 2005 11:01 pm
by Sphenn
Ok, this is weird. I wrote the code out again, and now it's working perfectly..

I don't know if anything changed, but it's working fine now.
Thanks for spending your time helping me Feyd.
Thanks again
Sphenn
Posted: Sat Nov 05, 2005 11:02 pm
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..
Posted: Sat Nov 05, 2005 11:04 pm
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
Posted: Sat Nov 05, 2005 11:11 pm
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

Posted: Sat Nov 05, 2005 11:13 pm
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