Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
jQuery / PHP - Embed image from external page

I'm currently working on a website that requires me to load the image source of an tag from an external website via jQuery or PHP in order to embed that image on my page, is there any way to do this maybe by XPath?

EDIT: Based on additional research I did - both before asking the question here and after - I have now found the solution. Sergey Ligus has given me the right approach. The problem why file_get_contents didn't work was that the page seemed to block this kind of requests and I had to fake a user_agent via stream_context_create.

Example:

$context = stream_context_create([
        'http' => [
                'user_agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)',
        ],
]);

$html = file_get_contents('URL', false, $context);
$dom = new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$result = '';
foreach ($xpath->query('XPATH') as $child) {
    $result .= $dom->saveHTML($child);
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found something that might answer your question...
https://stackoverflow.com/questions/22580458/how-to-load-image-from-external-url-in-jquery-wordpress-theme
If this doesn't answer your question, I can tell you how to do this in vanilla JS :)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda