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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:22:27+00:00 2026-06-17T16:22:27+00:00

I have the following jquery: $(.download).click(function(){ $.post(‘get_bot.php’, url_code=+url_code, function (response) { alert(response); }); });

  • 0

I have the following jquery:

$(".download").click(function(){     
  $.post('get_bot.php', "url_code="+url_code, function (response) {
    alert(response);
  });
});

url_code is a variable that has the url for a json structure, here is a live example of the return:
https://services.sapo.pt/Codebits/botmake/01,02,03,04,05,06,07,08,I%20Rule!

Those numbers are parameters to generate different images.

On my get_bot.php page I’m doing:

$urlc=$_POST['url_code'];
$bot = file_get_contents($urlc);
header("content-type: image/png");
echo $bot;

I’m looking into ways on how to get a response as a .png file download, so when the user clicks .download there is a download window prompt with the .png file.

Passing in a correct url and echoing the file_get_content results seems to work fine (although if I try to right click and save the image, it actually saves the php file…)

Any help with this would be great, I’m not very experienced with json structures, so far I’ve only dealt with array structures, never an image output.

I’m aware I’m probably way off here on getting an actual result, but any pointers would be appreciated.

  • 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-17T16:22:28+00:00Added an answer on June 17, 2026 at 4:22 pm

    RFC2616 describes what you need to do. Basically, you need to add

    Content-Disposition: attachment; filename="fname.ext"
    

    To the header if I’m not mistaken.

    EDIT
    Here is a sample script. I’ve confirmed that this works on two of my servers with different setups.

    <?php
      header("content-type: image/jpg");
      header("Content-Disposition: attachment; filename='pic.jpg'");
      readfile('http://lorempixel.com/400/200/');
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following jQuery code. $(function() { $('.clickme').click(function() { $('.totalthing').slideToggle('slow','easeInOutQuart', function() { //
I have the following jquery script: $(function(){ $('#top-menu').on('click', 'a.change-menu', function(e){ e.preventDefault() $(#menu-change-div).load($(this).attr(href)); }); });
I have the following jQuery code, which works fine: $(document).ready(function () { $('#link1').click(function ()
I am trying to create download link using jQuery post() method as following: $.post('file.php',
I have the following jquery code: $(document).ready(function() { $(body[class*=page-calendar-practices] #content-header h1#title).after(<div id='athletics_practice-schedule'><div id='inner-title'><a href='www.example.com'
I have the following jquery function that submits to an iframe. The message sent
I have the following JQuery function being attached to the blur event of n
I have the following jquery: jQuery.fn.slideFadeToggle = function(speed, easing, callback) { return this.animate({ opacity:
I have following jquery: $(window).resize(function () { changeIframe(); }); $(#iFrame).load(function () { changeIframe(); });
I have following jquery code plugin: (function ($) { $.fn.extend({ collapsiblePanel: function () {

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.