0

When i try run this file i am getting this error.

<?php

$im = imagecreatetruecolor(100, 100);

// sets background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp1\htdocs\check\2.php:1) in C:\xampp1\htdocs\check\2.php on line 7
�PNG  ��� IHDR���n������V,����PLTE����[an����fIDAT�c`�`fx���`Ǡ����41����˖ݒ�q�@੤;{á0� �i 
hakre
  • 193,403
  • 52
  • 435
  • 836
goblin2986
  • 971
  • 3
  • 16
  • 32

3 Answers3

2

If that is the complete script, and there really is nothing shown in front of the opening <?php tag (your editor may have a 'visible white space' option that would show anything), another thing it may be is the file has been saved as UTF8, and has a 'BOM' as the first couple of characters in the file. Resaving it as plain text (maybe 'ANSI') may improve matters.

Another possibility is that a file is being prepended before the script is being run. That may have output in it, or trailing content after a closing php tag (my advice - don't have a closing PHP tag unless specifically required).

Move the header('Content-type: image/png'); to the top of the script won't hurt, unless there really is something being output before the opening tag.

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110
0

Alister said pretty everything about what could causes that error, but there is one more thing. PHP might throw some error/warning/notice. Remove the header and check whether there is no errors.

Crozin
  • 43,890
  • 13
  • 88
  • 135
0

Use this given code...i hope u will not find any error