daljeetseni Posted July 23, 2015 Share Posted July 23, 2015 Hi, I am trying to save an external file on my server which is like http://website.com/download.php?id=55134 file_get_contents does not work neither curl works, basically, this page should be loaded and then this id will be called, On my server exec command is disabled. so any other way, i can do this ? Thanks. Daljeet Quote Link to comment Share on other sites More sharing options...
iarp Posted July 23, 2015 Share Posted July 23, 2015 file_get_contents needs allow_url_fopen = 1 in your php.ini to allow downloading files from an external source. curl may need to be enabled in your php.ini or you need to post the curl code so we can check it. Is display_errors = On in your php.ini? Quote Link to comment Share on other sites More sharing options...
daljeetseni Posted July 23, 2015 Author Share Posted July 23, 2015 (edited) Hi thanks for reply, here is my code, with file_get_contents which work perfectly for files with extensions like .pdf, .mp3 e.t.c, error_reporting(E_ALL); ini_set('display_errors', 1); $url =urldecode(trim($_POST['url'])); $content = file_get_contents($url); $name=basename($url); $fp = fopen($name, "w"); fwrite($fp, $content); fclose($fp); echo "<a href='".$name."'>".$name."</a>"; and here is the curl code: error_reporting(E_ALL); ini_set('display_errors', 1); $source = "http://website/file.php?id=123"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION,3); $data = curl_exec ($ch); $error = curl_error($ch); curl_close ($ch); $destination = "test.mp3"; $file = fopen($destination, "w+"); fputs($file, $data); fclose($file); In case of loading the curl script, it does not give any error, but writes a 0 byte file named test.mp3 what i want is, the code should work even for files which are not having extension meaning, which are called by id like for example, http://website/file.php?id=123 so, i want to load this type of url in php script which can grab the file, if that is possible . Edited July 23, 2015 by daljeetseni Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.