Jump to content

downloading content from url in array


DaGeek247

Recommended Posts

Alrighty, I have posted about this before, but for a very different question. So different, i figured it merited a different post. anyways...

 

I have a php script that downloads a webpages html code, then shows that code as its own on another server. I got it to work great, but it does not download/show the images and css. Using <base href> works great for the links, but the images are an issue, along with the css.

 

Here's what I have got so far: (any scripts or other stuff is greatly appreciated)

<?php
//download the webpage
$contents = file_get_contents($url);
//we have downloaded the html from the page,
//but not the external files such as css, and images
//so now we add the images and css
//start by splitting it into an easy to manage array
$contentchunks = explode("/n", $contents);

//mess with the html we downloaded
foreach($contentchunks as $varname => $varval){ //varval is the single line of html
  //go through every line of the html code and replace it to my heart's content
  if(stristr($varval, 'src=') === TRUE) { //check to see if has what im looking for
    //get the url to download
    
    //download and insert the image
  }
}

//put the modified array back together
$contents = implode("/n", $contentchunks);
//view the webpage
echo $contents;
?>

I have a demonstration of what it does over at http://dageek247.tk/viewit/

Link to comment
Share on other sites

Andy-H, im not sure if your link was sarcastic, or serious. either way, I had no idea what i was doing had been done before, so thanks. I think i got it now. im using my own modified version of http://www.doncaprio.com/2011/01/how-to-create-free-php-proxy-site.html And its working a lot better than what i ever thought i could acheive with my resources / knowledge. *solved*

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.