Jump to content

Downloading files with php using http


Asheeown

Recommended Posts

You didn't answer my first question.

 

PHP fsock with HTTP isn't any more special than your web browser. If you go to the url and see a webpage, then PHP will see a webpage. If there isn't an index file and you can see all the files in your browser, then PHP will see that file list.

 

If there is an index, then you can not do this. Not unless you know the file names ahead of time (or you scrape the page for file names).

The index page that apache/IIS generates is a HTML document. Scrape it just like one.

 

<?php
$page = file_get_contents("http://www.kodb.info/patches/");

$page = strip_tags($page);

echo $page;

 

You can explode that by newline, then run through it and remove the stuff you don't want (anything other than file names).

 

Once you get it down to an array of file names, then you can start working on the downloading part.

Use the string functions.

 

This would be a start to my example page:

<?php
$page = file_get_contents("http://www.kodb.info/patches/");
$page = substr($page, strpos($page, "<HR>")); 
$page = substr($page, strpos($page, " - ") + 4); 
$page = substr($page, 0, strpos($page, "Apache/1.3.37 Server at www.kodb.info Port 80"));
$page = strip_tags($page);
$page = trim($page);

echo $page;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.