Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6707871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:41:27+00:00 2026-05-26T07:41:27+00:00

I have a jquery form that posts to a callback page. The callback page

  • 0

I have a jquery form that posts to a callback page. The callback page uses PHP’s GD library to create an image.

The PHP code looks like this:

<?php
include 'inc/config.php';

$caseNum = $_POST['caseNum'];
$wish = $_POST['wish'];
$selectedWishes = join(", ", $wish);
$fname = $_POST['fname'];
$middlename = $_POST['middlei'];
$lname = $_POST['lname'];
$address1 = $_POST['adr1'];
$address2 = $_POST['adr2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$recipt = $_POST['recipt'];

$terms_accepted = $_POST['tou'];

if ($terms_accepted == 'accept') {

    mysql_connect($db_host, $db_user, $db_pass);
    mysql_select_db($db_database);

    $select = mysql_query('SELECT * FROM children WHERE caseNumber="'.$caseNum.'" LIMIT 1 ');
    $row = mysql_fetch_array($select);

    header('Content-type: image/png');
    $im = imagecreatefrompng ("images/card_bg.png");
    $color = imagecolorallocate($im, 0, 0, 0);
    $font = 'inc/fonts/MyriadPro-Regular.otf';
    $size = 14;
    imagettftext($im, $size, 0, 130, 18, $color, $font, $caseNum);
    imagettftext($im, $size, 0, 52, 105, $color, $font, $row['age']);
    imagettftext($im, $size, 0, 108, 167, $color, $font, $row['name']);

    // Print wishes and word wrap
    $lines = explode('|', wordwrap($selectedWishes, 30, '|'));
    $y = 238;
    foreach ($lines as $line) {
    imagettftext($im, $size, 0, 18, $y, $color, $font, $line);
    $y += 23;
    }

    imagettftext($im, $size, 0, 339, 151, $color, $font, $fname.' '.$middlename.' '.$lname);
    imagettftext($im, $size, 0, 351, 175, $color, $font, $address1);
    imagettftext($im, $size, 0, 365, 196, $color, $font, $address2);
    imagettftext($im, $size, 0, 326, 218, $color, $font, $city);
    imagettftext($im, $size, 0, 474, 218, $color, $font, $zip);
    imagettftext($im, $size, 0, 340, 242, $color, $font, $phone);
    imagettftext($im, 9, 0, 333, 268, $color, $font, $email);

    if ($row['gender'] == 'male') {
        $check = imagecreatefrompng('images/checkmark.png');
        imagealphablending($check, true);
        imagesavealpha($check, false);
        imagecopymerge($im, $check, 74, 3, 0, 0, 10, 15, 80);
    }
    else if ($row['gender'] == 'female') {
        $check = imagecreatefrompng('images/checkmark.png');
        imagealphablending($check, true);
        imagesavealpha($check, false);
        imagecopymerge($im, $check, 74, 38, 0, 0, 10, 15, 80);
    }

    if ($recipt == 'yes') {
        $check = imagecreatefrompng('images/checkmark.png');
        imagealphablending($check, true);
        imagesavealpha($check, false);
        imagecopymerge($im, $check, 324, 383, 0, 0, 10, 15, 80);
    }
    else if ($recipt == 'no') {
        $check = imagecreatefrompng('images/checkmark.png');
        imagealphablending($check, true);
        imagesavealpha($check, false);
        imagecopymerge($im, $check, 367, 383, 0, 0, 10, 15, 80);
    }


    $imageName = rand();
    $ourFileName = $imageName.'.png'; 
    $ourFilePath = 'images/created_tags/';

    imagepng ( $im, $ourFilePath.$ourFileName );

    imagepng($im);
    imagepng($check);
    imagedestroy($check);
    imagedestroy($im); 

    readfile ( $ourFileName );

print $ourFilePath.$ourFileName;

    exit ();  

}


?>

and here is the jQuery:

$.post('selectChildCallback.php', $("#select_child_form").serialize(), function(data) {

                $("#post_image").append('<img src="'+ data.path +'" alt="card" />');

            }, 'json');

What I can’t figure out is how to make the callback page not display the image, but just the path. Right now it prints the image data instead of an image path.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:41:27+00:00Added an answer on May 26, 2026 at 7:41 am
    readfile ( $ourFileName );
    

    This line is the problem. According to the docs, it echos the contents of a file to the screen. So PHP is returning a image file (binary) with its file name concatenated to the end of the stream back to jQuery.

    Remove this line, and this should work.

    EDIT:

    imagepng ( $im, $ourFilePath.$ourFileName );
    
    imagepng($im);
    imagepng($check);
    

    Why do you call imagepng 3 times? If you don’t give it a second parameter, it echos the image to the screen. Also remove the last 2 imagepng lines. PHP is actually returning 3 images concatenated together as well as the file name.

    It should look like this:

    $imageName = rand();
    $ourFileName = $imageName.'.png'; 
    $ourFilePath = 'images/created_tags/';
    
    imagepng($im, $ourFilePath.$ourFileName);
    
    imagedestroy($check);
    imagedestroy($im); 
    
    echo $ourFilePath.$ourFileName;
    
    exit();  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that uses jQuery to submit an ajax post and it
I have a method set up that uses jquery form for a file upload
I have a form that posts data through JQuery to a Controller that then
I have a page with a form that posts to salesforce.com's webto Lead service.
I have a jQuery dialog that posts a form when the Please Confirm button
I have started using jQuery and rails. I have made a simple form that
I have a form that I pre-populate with test data though jQuery. $('INPUT[name=subscription.FirstName]').val('Jef'); but
I have an Ajax contact form that links to a jquery file but for
I have a small jQuery plugin that I use for form AJAX validation. There
I have my front end script which has the following jQuery code: $.get(/backend/post.php, {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.