-1

Hi i have this curl to download link files from the sendthisfile.com. Now my problem is when I try to test it last week my code runs well. But now when I test it this is what I got to my web app. I suspect this is from the curl when processing the files. Can someone help me figured this thing out? this is my code below in curl

$zipUrl = "https://download.com/sample.zip";
$fileName = date().".zip"; //create a random name or certain kind of name here
                
                                  $fh = fopen($filename, 'w');
                                  $ch = curl_init();
                                  curl_setopt($ch, CURLOPT_URL, $zipUrl);
                                  curl_setopt($ch, CURLOPT_FILE, $fh); 
                                  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // this will follow redirects
                                  curl_exec($ch);
                                  curl_close($ch);

can someone help me why this throws a texts in a webpage?

the is the screenshot

Programmer
  • 13
  • 5

1 Answers1

2

You're missing this:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

This tells curl to return the output instead of directly displaying it. It's also noteworthy that you should set CURLOPT_RETURNTRANSFER before CURLOPT_FILE as I've read here.

See the official documentation for more information.

KhorneHoly
  • 4,666
  • 6
  • 43
  • 75