Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    header( "Content-type: image/png" ); not working

    when i first pull up my webpage the png file shows up but when i submit a different image all i get is garbage on the screen like:
    �PNG  IHDR�<虻�PLTEK7(�oL�g8��l�zFӜh�n=ɯ��Ŗ�׹��Oԗ\깇�tBŋU�U-.$������e��m[L�Z2κ�UON�̤tJ'���Nܢg�ue8)!���jE'꽔�������ŴUC5daaxcQ��v~~~צz8QL��{��Ȭ��yX:��o'''��������l��������Ү�� �ʒ]!�d?aJ7~R,���C.!���Ĥ|Ktkqpp������t���ӿ����Ͷ�^3(96�l=�������wOeQA��؍[.j] #!�����������b:96͜~W���~NA0'}N(sO1��ΰ���$/,Z;#ᲊ/EB��u��������w���ӓT�b4�~Gڝa��`̎R�xwwc@$�Ϡ>`[ݝZ�z���IEE����

    myfirstpage.php

    Code:
     <form action="created_banner.php" method="post" id="banner_creator_form">
    	<div id="banner_generator">
    		<input type="hidden" name="banner_design" id="banner_design" />
    		<input type="hidden" name="banner_fontstyle" id="banner_fontstyle" value="verdana" />
    		<input type="hidden" name="banner_fontsize" id="banner_fontsize" value="12" />
    		<input type="hidden" name="banner_fontcolor" id="banner_fontcolor" value="ffffff" />
    		<input type="hidden" name="banner_textx" id="banner_textx" value="0" />
    		<input type="hidden" name="banner_texty" id="banner_texty" value="0" />
    
    		<div id="banner_preview_container">
    
    this is the form that posts the new file name
    mysecondpage.php
    Code:
    $img = $_POST [ banner_design ];
    if ( $img == "" ){ $img = "blank-banner"; }
    //$banner_text = $_POST [ banner_text_content ];
    //$banner_fontstyle = $_POST [ banner_fontstyle ];
    //$banner_fontsize = $_POST [ banner_fontsize ];
    //$banner_fontcolor = $_POST [ banner_fontcolor ];
    //$banner_textx = $_POST [ banner_textx ];
    //$banner_texty = $_POST [ banner_texty ];
    $this_img = "images/free-banner/".$img.".png";
    $my_img = imagecreatefrompng ( $this_img );
    $background = imagecolorallocate( $my_img, 0, 0, 255 );
    $text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
    $line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
    imagestring( $my_img, 4, 30, 25, $banner_text, $text_colour );
    imagesetthickness ( $my_img, 5 );
    imageline( $my_img, 30, 45, 165, 45, $line_colour );
    header( "Content-type: image/png" );
    imagepng( $my_img );
    imagecolordeallocate( $my_img, $background );
    imagecolordeallocate( $my_img, $text_colour );
    imagecolordeallocate( $my_img, $line_colour );
    imagedestroy( $my_img );
    this is the page that should display the image with text... when i first pull the page up the blank-banner.png shows fine but when i submit a new file name all i see is garbage. i have been fighting this for some time now and cannot figure it out.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Looks to me that your headers are already sent.
    Is that exactly the code in the mysecondpage.php? And is that exactly the output? Given what I see in the first line of mysecondpage.php, you have an error on the first line.

  • Users who have thanked Fou-Lu for this post:

    hddctr (07-20-2012)

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    mysecondpage.php is exactly the code i'm using, i think the trees are blocking my view to the forest, i dont see the error you are referring to, i tried moving the header ( Content to the first line and it makes no difference

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This is invalid:
    PHP Code:
    $img $_POST banner_design ]; 
    banner_design has not been declared as a constant in this code. Assuming that's a string, that should be
    PHP Code:
    $img $_POST ['banner_design'];
    // or
    $img $_POST ["banner_design"]; 
    If that's the exact code you are using, I'm not sure how you are getting any output other than PHP code. This is missing the <?php tags required to start the PHP engine.

    Moving the header will only make a difference if its before all output. If error's are being spit out before the header is sent, then it will fail to push the header as well. This has to be before any output whatsoever.

  • Users who have thanked Fou-Lu for this post:

    hddctr (07-20-2012)

  • #5
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    sorry your right i didnt include the <?php tags in the copy some forums don't allow it.

    this is the exact code:

    [CODE]
    <?php
    $img = $_POST['banner_design'];
    if ( $img == "" ){ $img = "blank-banner"; }
    //$banner_text = $_POST [ banner_text_content ];
    //$banner_fontstyle = $_POST [ banner_fontstyle ];
    //$banner_fontsize = $_POST [ banner_fontsize ];
    //$banner_fontcolor = $_POST [ banner_fontcolor ];
    //$banner_textx = $_POST [ banner_textx ];
    //$banner_texty = $_POST [ banner_texty ];
    $this_img = "images/free-banner/".$img.".png";
    $my_img = imagecreatefrompng ( $this_img );
    $background = imagecolorallocate( $my_img, 0, 0, 255 );
    $text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
    $line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
    imagestring( $my_img, 4, 30, 25, $banner_text, $text_colour );
    imagesetthickness ( $my_img, 5 );
    imageline( $my_img, 30, 45, 165, 45, $line_colour );
    header( "Content-type: image/png" );
    imagepng( $my_img );
    imagecolordeallocate( $my_img, $background );
    imagecolordeallocate( $my_img, $text_colour );
    imagecolordeallocate( $my_img, $line_colour );
    imagedestroy( $my_img );
    //echo "<br /><br /><img src='".$this_img."'><br />".$banner_text."<br />".$banner_fontstyle."<br />".$banner_fontsize."<br />".$banner_fontcolor."<br />".$banner_textx."<br />".$banner_texty;
    ?>
    [CODE]

    i changed to [ICODE]$img = $_POST['banner_design'];[ICODE] but i am still getting the same result

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Enable your error reporting:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    For the first lines of the code, then run it. Does it pump errors for headers sent? If so, post those errors.

  • Users who have thanked Fou-Lu for this post:

    hddctr (07-20-2012)

  • #7
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i placed it on the first line and removed the rem [ICODE]$banner_text = $_POST ['banner_text_content'];[ICODE] and got no errors but a lot of garbage

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Comment out the imagepng(). Keep the error reporting enabled, and run it again.
    What is the output you get?

  • Users who have thanked Fou-Lu for this post:

    hddctr (07-20-2012)

  • #9
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    believe it or not i "just" resolved that problem but have created a new one...

    im using javascript to direct the image to a certain <div> container

    [CODE]

    $(document).ready(function(){
    $('#banner_creator_form').ajaxForm({
    target: '#created_banner',
    beforeSubmit: function(){
    if(!design_chosen) {
    alert('Please select a banner design.');
    return false;
    }
    var pos = $("#banner_text").parent().position();
    var left = pos.left;
    var top = pos.top;

    $("#banner_textx").val(left);
    $("#banner_texty").val(top);
    //alert(left);
    //alert(top);
    $('#created_banner').php('<img src="images/free-banner/loading2.gif" />');
    },
    success: function(){}
    });
    $("#banner_text").draggable({
    stop: function(event, ui){
    alert("ASDSA");
    }
    });
    });
    [CODE]

    and had .html where .php is now...

    but my new problem is that the image is not displaying in the #created_banner <div> its displaying on a parent page by itself... got any ideas?

  • #10
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    I just see tons of things that are either wrong, or could be greatly simplified. Whenever you use a form, and post or get, you should wrap the working code on the download page in an isset($_POST['some input name here'] statement. If you have defaults you need to have an !isset ( not isset ) statement too. For one your first input has no declared value. If you're using javascript to gather data and fill out the form, it's still a good idea to have default values. You can make all your inputs an array like this: name="myins[]".

    Forms are one of the things that are really important to learn in php, and php really does them well. If you want something important to learn and practice on in php you can't do better than forms. And arrays, too, I use them wherever I can because php does them well too. I've reached the point where I can write a form and submission page from the top down, using arrays as much as I can to simplify my code, and with very few errors, and that would be a good goal for anyone who wants to learn php.

  • #11
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i appreciate your comments DrDos, and i'm sure you are quite the coder but your reply doesn't get me any closer to solving my issue, but i will be sure to ask for you when i have issues writing a form and submission page with arrays in fact if you'll write the book i'll be sure and pick up a copy.

  • #12
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by hddctr View Post
    i appreciate your comments DrDos, and i'm sure you are quite the coder but your reply doesn't get me any closer to solving my issue, but i will be sure to ask for you when i have issues writing a form and submission page with arrays in fact if you'll write the book i'll be sure and pick up a copy.
    There are a lot of people here who are more proficient that I, I consider my level a sort ot minimum, but it's important to reach that minimum. Your issue isn't just one, it's several, no one here is likely going completely rewrite your form, since none of us quite entirely know how you are using it.

  • #13
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    sir, being the dumb *** that i am i might not be able to write the code that someone of your caliber can but i am learning and part of learning is asking questions and asking someone else to look at a problem so hopefully someone who knows or has had the same issue in the past can point me in the right direction. i really don't remember asking if someone could re-write my code just simply looking for pointers which Fou-Lu was so kind to do (thank you for your help). i chose this forum because it looked like a group of coders that really didn't mind helping others out. are you a moderator? if you are then your the type of moderator that gives "help forums" a bad reputation, if not then your on this forum for the same reason i am, you got stuck on a problem and had to ask someone else. this issue is closed.

  • #14
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by hddctr View Post
    sir, being the dumb *** that i am i might not be able to write the code that someone of your caliber can but i am learning and part of learning is asking questions and asking someone else to look at a problem so hopefully someone who knows or has had the same issue in the past can point me in the right direction. i really don't remember asking if someone could re-write my code just simply looking for pointers which Fou-Lu was so kind to do (thank you for your help). i chose this forum because it looked like a group of coders that really didn't mind helping others out. are you a moderator? if you are then your the type of moderator that gives "help forums" a bad reputation, if not then your on this forum for the same reason i am, you got stuck on a problem and had to ask someone else. this issue is closed.
    No, I'm not a moderator, and I just help people out too, but you sort of have too many problems all at once, not just few. Just because I'm telling you something that you don't want to hear doesn't make me bad person. You can look on the side panel and see how many posts I've made and how many people bothered to thank me. I'm being kind too because I'm telling you something you need to know, even though you may not appreciate it now.

  • #15
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Everyone be calm yes. Thanks :]

    I can't really help you with the JS aspect I'm afraid; providing that in the JS forum will let the Client Side developers take a looksee. You may need to give a live link for it.

    DrDOS is right in the sense that you should start into good habits early.
    So with PHP code, you always need to do a check if it exists (but don't choose a submit button as your check as IE does not provide this as successful if the form has <= 1 input element within it). So that's a simple branch in your code:
    PHP Code:
    if (isset($_POST['banner_design']))
    {
         
    $img $_POST['banner_design'];
         
    // ... rest of processing here.
    }
    else
    {
        
    // Given the purpose of this script, I'd put a default image to show in here.

    That gets around a notice that you receive when you attempt to access an offset that doesn't exists. So if the form wasn't submitted to get here for example, it will throw tons of errors unless it is checked.

    Same is done for some of the function calls. Using things like imagecreatefrom* you want to check that it successfully creates the image (whilst suppressing errors):
    PHP Code:
    if ($im = @imagecreatefromjpg($sImagePath))
    {
        
    // if your here, then it successfully created the image from the path
    }
    else
    {
        
    // default image (assuming this script serves as an image)

    Hope that helps!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •