-3

Here is my code:

<?PHP
$details1=json_decode(file_get_contents("http://2strok.com/download/download.json"));
$details2=json_decode(file_get_contents($details1->data));
echo "{$details2->data}";
?>

I do found some php code there i can force file to download but, i want to connect it with the result of download.json to be forced downloading.

Forece downloading example:

$file_url = 'http://www.test.com/forece-file.mp3';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . 
basename($file_url) . "\""); 
readfile($file_url);
Zabi
  • 23
  • 9
  • Just put the `header()` lines from the second block above your code in the first block. – Mike Feb 27 '18 at 01:52
  • @Mike Could give me an example? i tried it, but still not any respons :O – Zabi Feb 27 '18 at 01:54
  • First, [get errors to display](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display). Do you get any output at all? Does the `echo` line above work? – Mike Feb 27 '18 at 01:57

1 Answers1

0

You can use file_get_contents like this:

<?php
$details1=json_decode(file_get_contents("http://2strok.com/download/download.json"), true);
$details2=json_decode(file_get_contents($details1['data']), true);

$file_url = $details2['data'];
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . 
basename($file_url) . "\""); 
readfile($file_url);
?>

Or you can use cURL:

<?php
$ch = curl_init();
$url = "http://2strok.com/download/download.json";

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$url2 = json_decode($output)->data;

curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$url3 = json_decode($output)->data;

curl_close($ch);     

header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($url3) . "\"");
readfile($url3);
?>
Adlan Arif Zakaria
  • 1,706
  • 1
  • 8
  • 13