English 中文(简体)
PHP 图像内容类型问题
原标题:PHP Image content type problem

我有一个具体问题,必须接手。

对于我的最新项目,我需要一份简单的PHP书,根据通过URL发送的身份证显示图像。 该法典:

header("Content-type: image/jpeg");
$img = $_GET["img"];
echo  file_get_contents("http://www.somesite.hr/images/$img");

问题在于,尽管浏览器承认图像,但图像确实显示(我可以在网页上看到),但我还是拿到电子版的URL图像。

It doesn t work neither on a server with remote access allowed nor with one without. Also, nothing is printed or echoed before the header.

I wonder if it is a content type error, or something else. Thanks in advance.

问题回答

Possibly the image doesn t fit into memory. Or your PHP installation doesn t have permissions to make external HTTP calls. Anyway, I suggest you never use echo file_get_contents(), use readfile instead. Also you should never use raw strings from $_GET or $_POST for file operations. Always strip null-bytes, slashes and double dots from user-provided filenames, or better yet, allow only alphanumeric characters.

我正像最近那样做一些事情,但发现这一方法很缓慢(我正用15+页)。 之所以如此缓慢,是因为首先,你的服务器必须下载图像,然后将其发送给客户。 这意味着每个图像都两次下载。

我提出了另一种选择,即方向调整。 这使得客户机器能够直接进入另一个网站,同时在超文本来源代码中隐藏真实的圆顶。

美元——在文字上处理,并作验证以确保其为ok。

$webFile =  http://www.somesite.com/ .$r[ type ]. / .$r[ productid ]. .jpg ;
header( Location:  .$webFile);
exit();

如果有人把我的图像ur在地址栏中,那会改头,使用者会看到真实的气味,但使我的网页更快,我对此感到太担忧。

你希望确保你的文字不会产生任何白色空间。 在开放/封闭式管道之前和之后进行检查。

如果进行这种检查,请确保<代码>allow_url_f open/code>被定在上。 On in php.ini

试图将检索<img>在您的html中的形象的 php 文档相贴

获得Image.php

header("Content-type: image/jpeg");
$img = $_GET["img"];
echo  file_get_contents("http://www.somesite.hr/images/$img");

页: 1

<img src="获得Image.php?img=IMAGEID">

或许你会发现一些错误,不展示形象。 3. 着手消除这种错误:

ini_set( error_reporting , E_ALL);
ini_set( display_errors ,  Off );

检查这些变量存在于盘点中,并使用定期表述确保它不包含除字母数字特征或一段期间以外的任何内容。 然后,将产出纳入浏览器。

// make sure the variable exists
if (isset($_GET[ image ])) {
    $image = $_GET[ image ];
    // make sure it contains only letters, numbers, the underscore, and a period
if (preg_match( /^[w.]+$/ , $image)) {
    $file = "http://www.example.com/images/$image";
    // send the correct header
    header( Content-type: image/jpeg );
    // stream the output
    readfile($file);
    }
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签