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

  • Home
  • SEARCH
  • 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 3694234
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:28:20+00:00 2026-05-19T04:28:20+00:00

The following code transfers an image that is created on the fly from a

  • 0

The following code transfers an image that is created on the fly from a server to a client site using cURL. It stopped working recently and have not been able to find out what the problem is:


    // get_image.php
    ob_start();

    // create a new CURL resource
    $ch = curl_init();

    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, 'url/to/image.php');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // set timeouts
    set_time_limit(30);                     
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);  

    // open a stream for writing
    $outFile = fopen($fileDestination, 'wb');

    curl_setopt($ch, CURLOPT_FILE, $outFile);

    // grab file from URL
    curl_exec($ch);
    fclose($outFile);

    // close CURL resource, and free up system resources
    curl_close($ch);
    ob_end_clean();

  //image.php

  /*
   * Create image based on client site ...
   */

  $filePath  = 'path/to/image.png'
  $imageFile = file_get_contents($filePath);

  header("content-type: image/png");        
  echo $imageFile;
  unlink($filePath);

The file get_image.php is located in a client site and calls the file image.php located in my server.

After running this code the image in the client site is about 7 bytes larger than the original, these bytes seem to be line breaks. After debugging for several hours I found out that these bytes are added when I echo $imageFile. If the 7 bytes are manually removed from the resulting image, the image displays correctly.

There are no errors nor exceptions thrown. The image created in the server is created with no issues. The only output in FF is “The image ‘url/to/image.php’ cannot be displayed, because it contains errors”

I am not sure what is causing this. Help is greatly appreciated.

  • Onema

UPDATE:
http://files.droplr.com/files/38059844/V5Jd.Screen%20shot%202011-01-12%20at%2012.17.53%20PM.png

http://files.droplr.com/files/38059844/QU4Z.Screen%20shot%202011-01-12%20at%2012.23.37%20PM.png

  • 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-19T04:28:21+00:00Added an answer on May 19, 2026 at 4:28 am

    Some things to check.

    That both files are stored without BOMs

    That ‘<?php’ are the first five characters and ‘?>’ the last two in both files.

    That when you remove the ob_start() and ob_end-clean(() it should show no error messages.

    If you put the unlink before the genereation, you can see the genereated file – check it is valid.

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

Sidebar

Related Questions

The following code should find the appropriate project tag and remove it from the
I'm new to C++ and inherited the following code that is supposed to transform
I have the following code in Python using Numpy: p = np.diag(1.0 / np.array(x))
i am using the following code <?php $rFile = $_GET['sfile']; $rExt = $_GET['ext']; header(Content-disposition:
I want to upload an image in Zend-framework. In Application_Form_Test.php I write following code....
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
The following code works great in IE, but not in FF or Safari. I
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
The following code illustrates an object literal being assigned, but with no semicolon afterwards:
The following code is in the /Courses/Detail action: [AcceptVerbs(GET)] public ActionResult Detail(int id) {

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.