1

I saw an answer that said that I could use copy to transfer the file. However I tried this, and it didn't work.

<?php
  $img = $_GET["img"];
  if($img){
    if(strpos($image, ".jpg") != -1){
      $ext = ".jpg";
    } else if(strpos($image, ".png") != -1){
      $ext = ".png";
    } else if(strpos($image, ".gif") != -1){
      $ext = ".gif";
    } else {
      die("Unsupported image type.");
    }
    $rand = rand(0, 100000);
    if(copy($img, "/images/" . $rand . $ext)){ echo "/images/$rand$ext"; } else { echo "Unsupported image type."; }
  } else {
    echo "Unsupported image type.";
  }
?>

The reason, as I found out, is because the copy function isn't working. I set the allow_url_fopen to on in my php.ini, so why isn't this working?

Community
  • 1
  • 1
yaakov
  • 4,568
  • 4
  • 27
  • 51
  • 1
    Are you getting an error? Offhand it looks like what you're trying to copy from can't be found: what are your inputs? What is `$img` at the point you're executing `copy`? Maybe put this in a try/catch block to get specific exceptions? – Nathaniel Ford Aug 17 '16 at 22:01
  • `Warning: copy(http://example.com/image.jpg): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/*******/public_html/image.php on line 14` – yaakov Aug 17 '16 at 22:06
  • So it was just the image that was the problem... is there any way I can get around a HTTP Forbidden? – yaakov Aug 17 '16 at 22:09
  • "Get around"? No: that code means you're not allowed to get (if it exists) the resource you're requesting. – Nathaniel Ford Aug 17 '16 at 22:15

0 Answers0