1

I have an xml feed that has some image urls provided in it . Each link contains one Images only,

I have to parse this url and download those images in some folder using PHP.

Something like this

while($xmlcontent = mysql_fetch_array($images)){

                         download_img($xmlcontent["tag"]);
                }
function download_img($im_url)
{


}

Thanks in Advance

Vikram Anand Bhushan
  • 4,836
  • 15
  • 68
  • 130

2 Answers2

2

Put this line in an htaccess file in the directory you want the setting to be enabled:

php_value allow_url_fopen On

then create a function as simple as this.

function download_file($file_url, $save_to)
{
    $content = file_get_contents($file_url);
    file_put_contents($save_to, $content);
}

usage:

download_file('http://example.com/images/logo.jpg', realpath("./downloads") . '/yourfile.jpg');
SO-user
  • 1,458
  • 2
  • 21
  • 43
1

I assume the URL can be anywhere? Try this:

$image = file_get_contents($url);
file_put_contents($filename,$image);

See: http://php.net/manual/en/wrappers.php

And yes, copy() should also work if you believe that page.

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
  • i tried this i used a folder in the current directory like this `$newFilePath = './server'; $data = file_get_contents($file); file_put_contents($newFilePath,$data);` But it says permission denied – Vikram Anand Bhushan Feb 27 '15 at 10:50
  • try: `$newFilePath = 'test';` and make sure you've got write permission in the current directory. See: CHMOD (in Linux: http://en.wikipedia.org/wiki/Chmod). – KIKO Software Feb 27 '15 at 10:52