file_get_contents - 也可以获得图片 [英] file_get_contents - also get the pictures
问题描述
各位大家好!我在PHP和file_get_contents编码时遇到了一个问题。我的问题是当我加载这样的网站时:
Hello there everybody! I've run into a problem lately when coding in PHP and file_get_contents. My problem is that when i load a website like this:
<? echo file_get_contents($_GET['url']); ?>
我加载的网站图片没有显示。例如,当我去Google时,没有显示图片。这是我访问的每个网站。我该如何解决这个问题?
The pictures of the website i load doesn't show. For example when I go to Google, no pictures are shown. This is for every website i visit. How can i fix this?
推荐答案
您正在显示的HTML页面假设您还有可用的图像,但您没有因为它们位于原始页面的服务器上(例如Google.com)。
The HTML page you are displaying assumes you also have the images available, which you don't as they are on the original page's server (e.g. Google.com).
确保加载HTML页面上所有内容的最快方法是添加< base href =http://www.google.com//>
。这告诉浏览器返回其他内容的原始路径,包括图像,CSS,脚本等。
The quickest way to make sure everything on the HTML page loads is to add <base href="http://www.google.com/" />
. This tells the browser to go back to the original path for the rest of the contents including images, CSS, scripts etc.
你想要在<您正在显示的HTML页面的code>< head>< / head> 。您可以使用正则表达式或简单HTML DOM。
You'll want to inject that between the <head></head>
of the HTML page you're displaying. You could use a regular expression or Simple HTML DOM.
希望有帮助
这篇关于file_get_contents - 也可以获得图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!