I found a way to upload an image, for example, but this can help with any kind of file. It downloads the file without using readfile .
I know this can be awkward, but sometimes we need workarounds to get the job done.
Try where $src = 'http://external-server/remote-image.jpg'
$url_stuff = parse_url($src); $port = isset($url_stuff['port']) ? $url_stuff['port'] : 80; $fp = fsockopen($url_stuff['host'], $port); $query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n"; $query .= 'Host: ' . $url_stuff['host']; $query .= "\n\n"; $buffer=null; fwrite($fp, $query); while ($tmp = fread($fp, 1024)) { $buffer .= $tmp; } preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=your_file.bin'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $content = substr($buffer, - $parts[1]); echo $content;
it is tested and working; -)
source share