tags:

views:

108

answers:

4

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 
+2  A: 

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
no its the complete script..i am trying to run this script on 1-2 servers imagecopymerge function works while this script fails?
bhaskaragr29
thanks i have set my encoding to UTf8...thats ahy i ws getting this problem...as soon as i set my encoding to ANSI it works :)
bhaskaragr29
so there was a BOM at the start of the file.
Alister Bulman
A: 

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
A: 
Anil Kumar
A: 

You have probably saved the file in Unicode encoding with a "signature". Looking at your code, line 1 contains <?php and nothing could be wrong with that so the signature problem is highly probable.

To workaround this, copy-paste your code in a blank notepad window and save the file, specify ANSI encoding on the Save As dialog. Or if you're using dreamweaver or some other tool, use the Save As command to save the file and look at the available "encoding" options. Choose settings that contain "without signature".

Salman A