-2

Suppose i have fetched a images using PHP Simple HTML DOM Parser and obtain it in a specific URL. Suppose it fetched a Image in a variable like

<?php include("simple_html_dom.php");
$webpage ="http://www.example.com";
$html = file_get_html($webpage);
foreach($html->find('img') as $element) {
echo $element->src . '<br>';  }
?>

Now is it possible to get this image in my own domain path, like
$new_img = 'http://mysite.com/some_image_address.JPEG';
I am a PHP beginner so please describe it

HasanTG
  • 63
  • 6
  • Yes, it is possible. Here's a good start to learn programming, and a new programming language (PHP): http://www.php.net/manual/en/. Easy and fun. Good luck :) – oxygen Sep 08 '12 at 10:10
  • You changed the code and your question. How can you expect a decent answer? – JvdBerg Sep 08 '12 at 11:08

2 Answers2

1

did you try vanilla php, you can try this
Example:

    <?php
function xsrc($url){
return "http://www.my_site.com/myfolder/" . basename($url);
}
//Two liner
$img = xsrc('http://www.example.com/free_images/treacle1.png');
echo "<img src='$img' />";
//One liner
echo '<img src="' . xsrc('http://www.example.com/free_images/treacle.png') . '" />';
//HEREDOC SYNTAX
echo <<<IMG
<img src="$img" />
IMG;
?>
<!-- HTML WITH INLINE PHP -->
<img src="<?php echo xsrc('http://www.example.com/free_images/treacle.png');?>" />
<img src="<?php echo $img;?>" />
blömpæ
  • 375
  • 2
  • 12
0

Why do you not right click the image on the site and choose 'Save image as'? No need to use PHP for that.

First learn the basics on browsing, before going into the programming profession!

Most images on other sites are copyrighted, so think twice before you rip a image from another site!

Update:

What you want to do is know as html crawling. First google on that, there a numerous examples. How do I make a simple crawler in PHP?

Community
  • 1
  • 1
JvdBerg
  • 21,777
  • 8
  • 38
  • 55
  • okay, i have basic knowledge on PHP and i know how to fetch a image, right. So just wanna know how to get it in a new url, and i am careful about copyright issue, need not make it your cup of tea.. – HasanTG Sep 08 '12 at 10:27