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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.