Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
jQuery / PHP: incrustar imagen desde una página externa

Actualmente estoy trabajando en un sitio web que requiere que cargue la fuente de la imagen de una etiqueta desde un sitio web externo a través de jQuery o PHP para incrustar esa imagen en mi página, ¿hay alguna forma de hacer esto tal vez con XPath?

EDITAR: Según la investigación adicional que hice, tanto antes de hacer la pregunta aquí como después, ahora encontré la solución. Sergey Ligus me ha dado el enfoque correcto. El problema por el que file_get_contents no funcionó fue que la página parecía bloquear este tipo de solicitudes y tuve que falsificar un agente de usuario a través de stream_context_create.

Ejemplo:

 $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 answers
Answer question

0

Encontré algo que podría responder a tu pregunta...
https://stackoverflow.com/questions/22580458/how-to-load-image-from-external-url-in-jquery-wordpress-theme
Si esto no responde a su pregunta, puedo decirle cómo hacerlo en Vanilla JS :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!