PHP cURL, just shows garbled text on page -


i trying download file on curl , save file, displays page garbled, believe it's showing contents of file. use fopen, i'm hoping allow follow redirects.

<?php $url = $_post["url"]; if(empty($url)){header('location: index.php'); exit;} $email = $_post["email"]; $domain = $_server['server_name'];  $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_connecttimeout, 0); curl_setopt($ch, curlopt_maxredirs, 3); curl_setopt($ch, curlopt_timeout, 0); $dl = curl_exec($ch); $filename = basename($url); echo "downloading $url ";  echo "<br>"; echo "to "; echo "<br>"; $downloadedto = 'http://' . $domain . '/downloads/' . $filename;  echo "<a href='$downloadedto'>$downloadedto</a>";    file_put_contents("downloads/$filename", $dl, 'r', lock_ex); if(!empty($email)){ mail ($email, "your cloud download complete!", "good news! cloud download of $filename finished!, please download before auto deleted our server $downloadedto"); } ?> 

@finwe , @va79 pointed out needed curl_setopt($ch, curlopt_returntransfer, 1); default curl returns true/false rather data :)


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -