Jump to content

Loading remote file with id


daljeetseni

Recommended Posts

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?

Link to comment
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
Link to comment
Share on other sites

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.