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 8128841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:03:46+00:00 2026-06-06T08:03:46+00:00

My server is running php and I want it to be able to send

  • 0

My server is running php and I want it to be able to send me images. For instance “profile.jpg”.

In C# i just populate a bitmap image with the source, but how do I create a source, a file that outputs the images binary data?

I have this:

<?php
$file = 'profil.jpg';
$image = imagecreatefromjpeg($file);
imagealphablending($image, false);
imagesavealpha($image, true);

// start buffering
ob_start();
imagepng($image);
$contents =  ob_get_contents();
ob_end_clean();

echo "<img src='data:image/jpeg;base64,".base64_encode($contents)."' />";

imagedestroy($image);
?>

But it outputs HTML, could i just echo base64_encode($contents)?

  • 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-06-06T08:03:48+00:00Added an answer on June 6, 2026 at 8:03 am

    I’d say you’re missing the headers and instead of cleaning the buffer you should flush it, something like that (off the top of my head)

    <?php
    $file = 'profil.jpg';
    $image = imagecreatefromjpeg($file);
    imagealphablending($image, false);
    imagesavealpha($image, true);
    
    // start buffering
    ob_start();
    
    header('Content-Description: File Transfer');
    header('Content-type: image/png');
    header('Content-Disposition: attachment; filename="'.$file.'"');
    header('Content-Transfer-Encoding: binary');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Pragma: public');
    
    imagepng($image);
    $contents =  ob_get_contents();
    
    // echo $contents;
    // ob_end_flulsh();
    /* OR */
    ob_get_fllush();
    
    echo "<img src='data:image/jpeg;base64,".base64_encode($contents)."' />";
    
    imagedestroy($image);
    ?>
    

    Something like that. You can of course add more information or have less in the header, depending on what you need at the other end. HTTP/1.1: Header Field Definitions. Also Output Control Fctns

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two websites running on my own root server (ubuntu/nginx/php-fpm). Now I want
We are running PHP on a Windows server (a source of many problems indeed,
I've got a web server running IIS7 and I just updated to PHP 5.3.
How to send messages from php to node.js? I have a linux server running
I send data from Android via HTTP Post to a Server running PHP and
We have a server running PHP 4.3.9 with safe_mode ON and safe_mode_exec_dir setted to
i am setting up cakephp app on a windows server running iis7. PHP is
I'm running server on Mandriva 2011 Apache 2.2.22 PHP 5.3.14 PHPUnit Version 3.3.17 Selenium
My client has PHP running on an IIS server, I know these vti_conf files
I'm running a php script from the command line against SQL server 2005 using

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.