Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/297443-loading-remote-file-with-id/
Share on other sites

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 by daljeetseni
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.