Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert Image To base64 while fetching them from other urls
    text
    copied!<p>I'm using a php to code to fetch images and data from the other urls but need to convert images to base64 string..!! the code is</p> <pre><code>&lt;?php function getMetaTitle($content){ $pattern = "|&lt;[\s]*title[\s]*&gt;([^&lt;]+)&lt;[\s]*/[\s]*title[\s]*&gt;|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 = '/&lt;img[^&gt;]*'.'src=[\"|\'](.*)[\"|\']/Ui'; preg_match_all($image_regex, $content, $img, PREG_PATTERN_ORDER); $images_array = $img[1]; $k=1; for ($i=0;$i&lt;=sizeof($images_array);$i++) { if(@$images_array[$i]) { if(@getimagesize(@$images_array[$i])) { list($width, $height, $type, $attr) = getimagesize(@$images_array[$i]); if($width &gt; 50 &amp;&amp; $height &gt; 50 ){ $data['images'] = "&lt;img src='".@$images_array[$i]."' id='".$k."' width='100%'&gt;"; $k++; } } } } $data['form'] = '&lt;input type="hidden" name="images" value="'.$data['images'].'"/&gt; &lt;input type="hidden" name="title" value="'.$data['title'].'"/&gt; &lt;input type="hidden" name="description" value="'.$data['description'].'"/&gt;'; $dom = new domDocument; @$dom-&gt;loadHTML($content); $dom-&gt;preserveWhiteSpace = false; $images = $dom-&gt;getElementsByTagName('img'); foreach($images as $img) { $url = $img-&gt;getAttribute('src'); $alt = $img-&gt;getAttribute('alt'); $pos = strpos($url, 'http://'); if ($pos === false) { // $data['images'] = '&lt;img src="'.$_POST['url'].''.$url.'" title="'.$alt.'"/&gt;'; } else { // $data['images'] = '&lt;img src="'.$url.'" title="'.$alt.'"/&gt;'; } } echo json_encode($data); ?&gt; </code></pre> <p><strong>This code use images in there Standard extension on this line</strong></p> <pre><code>$data['images'] = "&lt;img src='".@$images_array[$i]."' id='".$k."' width='100%'&gt;"; </code></pre> <p>I want to convert them to base64 and them use </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload