나는 다른 URL에서 이미지와 데이터를 가져 오기 위해 PHP를 사용하고 있습니다. 하지만 이미지를 base64 문자열로 변환해야합니다 .. !! 코드는이 라인이 표준 확장에변환 이미지 다른 URL에서 가져 오는 동안 base64하려면
<?php
function getMetaTitle($content){
$pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui";
if(preg_match($pattern, $content, $match))
return $match[1];
else
return false;
}
function fetch_record($path)
{
$file = fopen($path, "r");
if (!$file)
{
exit("Problem occured");
}
$data = '';
while (!feof($file))
{
$data .= fgets($file, 1024);
}
return $data;
}
$url = $_POST['url'];
$data = array();
// get url title
$content = @file_get_contents($url);
$data['title'] = getMetaTitle($content);
// get url description from meta tag
$tags = @get_meta_tags($url);
$data['description'] = $tags['description'];
$string = fetch_record($url);
// fetch images
$image_regex = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
preg_match_all($image_regex, $content, $img, PREG_PATTERN_ORDER);
$images_array = $img[1];
$k=1;
for ($i=0;$i<=sizeof($images_array);$i++)
{
if(@$images_array[$i])
{
if(@getimagesize(@$images_array[$i]))
{
list($width, $height, $type, $attr) = getimagesize(@$images_array[$i]);
if($width > 50 && $height > 50){
$data['images'] = "<img src='"[email protected]$images_array[$i]."' id='".$k."' width='100%'>";
$k++;
}
}
}
}
$data['form'] = '<input type="hidden" name="images" value="'.$data['images'].'"/>
<input type="hidden" name="title" value="'.$data['title'].'"/>
<input type="hidden" name="description" value="'.$data['description'].'"/>';
$dom = new domDocument;
@$dom->loadHTML($content);
$dom->preserveWhiteSpace = false;
$images = $dom->getElementsByTagName('img');
foreach($images as $img)
{
$url = $img->getAttribute('src');
$alt = $img->getAttribute('alt');
$pos = strpos($url, 'http://');
if ($pos === false) {
// $data['images'] = '<img src="'.$_POST['url'].''.$url.'" title="'.$alt.'"/>';
} else {
// $data['images'] = '<img src="'.$url.'" title="'.$alt.'"/>';
}
}
echo json_encode($data);
?>
이 코드 사용 이미지
$data['images'] = "<img src='"[email protected]$images_array[$i]."' id='".$k."' width='100%'>";
내가 64 기수로 변환 할 당신이 URL을 일단 그들이
[base64_encode] (http://php.net/base64_encode) – deceze
나는 이것을 시도했다 !! !! 하지만 제대로 작동하지 않습니다 .. !! 내가 어디 잘못된지 모르겠다 .. !! –
@Basic Bridge : 잘 모르겠지만 이미지를 가져 오지 않고 페이지 자체 만 가져옵니다. 다른 것을하기 전에'file_get_contents()'를 사용하여 이미지를 가져 오십시오. 당신이 할 일은 너비 높이와 이미지 URL에서 다른 쓰레기를 확인하는 것입니다 (이해가 안되네요). – xfix