-3

I have to download an image in a weblink to my local folder using php. Below is the program.

<?php

 if (isset ($_POST['submit'])){

  $URL = 'http://10.251.13.7/gtz/temp3.php/download.png'; // Like "http:// ...." 

  $FileToSave = 'uploads/download.png'; // Like "/home/.." or "C:/..." 

  $Content = file_get_contents($URL);

 file_put_contents($FileToSave, $Content); //file_put_contents('uploads/image.jpg',file_get_contents('10.251.13.7/gtz/temp3.php/mtps_files.png'));

  } ?>

I could successfully download the image. But when I try to open it's showing the file has been damaged. In one way I am able to right click the image in the weblink and save the file to my local directory. It works.

On the other hand, in php programming I was able to download the file and when I access the file, it is showing as file got damaged.

mario
  • 144,265
  • 20
  • 237
  • 291

1 Answers1

0

Please review below code. Please assign the home folder path in file & save file.

$URL = 'C:/home/demo/Downloads.png'; // Like "http:// ...." 

$FileToSave = 'D:/demo/download.png'; // Like "/home/.." or "C:/..." 

$Content = file_get_contents($URL);

file_put_contents($FileToSave, $Content); 
VinothRaja
  • 1,405
  • 10
  • 21