【发布时间】:2012-04-06 06:08:54
【问题描述】:
我正在寻找一种将存储在不同服务器上的 MySQL 数据库中的图像保存到我当前正在使用的服务器上的目录的方法。我正在检索 JSON 数据,每个条目都显示一个直接链接到 存储在数据库中的图像的 url。这是我目前正在做的,没有成功。
<?php
$url = 'https://secure.example.com/app/api?accountid=000&apikey=000&action=getview&format=json&viewid=0000&tableid=0000';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$imageList = json_decode($response,true);
$x = 1;
foreach ($imageList as $imageItem) {
$img = $imageItem['face_image'];
echo "<img src='" . $img . "' width='150' height='200'/>"; //THIS WORKS, DISPLAYS IMAGES
$dest_dir = "/uploads/"; //THIS DIRECTORY IS 777 CURRENTLY
$src_file = $img;
file_put_contents($dest_dir.$x.".jpg", $src_file);
$x++;
}?>
【问题讨论】: