我有以下php文件,用于读取和读取数据库中的图像
<?php
require_once('database.php');
$db = new Database();
$id = $_GET['id'];
$order = $_GET['order'];
// do some validation here to ensure id is safe
header('Content-type: image/jpeg');
echo pg_unescape_bytea($db->getImageById($id, $order));
?>
此文件工作正常,但是下面是我的使用方式
$img_binary = file_get_contents('http://example.com/helper/getImageById.php?id=' . $id . '&order=1', false);
$img_base64 = base64_encode($img_binary);
我正在尝试寻找一种方法,不再需要提供诸如example.com
之类的硬编码信息,我希望能够将所有文件移动到另一台服务器和/或域名而无需必须更改服务器IP。这是一个脚本,将被多个域名使用。
如何实现?
答案 0 :(得分:0)
使用$_SERVER["HTTP_HOST"]
代替域名。