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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:24:36+00:00 2026-06-14T15:24:36+00:00

I am using an ajax call to pass a value. I have done that

  • 0

I am using an ajax call to pass a value. I have done that and I want to take that value and do a lookup on my tables for a particular image.

When I get to the image to download, it is not working for me. I looked on my php.ini file and my allow_furl_open is off. I think this may be the culprit. Please disregard the mysql bits as I know it should be updated, this is not my code so that will be changed.

Here is the code.

if (isset($_POST['download'])) {
$sql = "SELECT `imageURL` FROM `digital_materials` WHERE `digital_materials`.`id` = '$id'";
$record = mysql_query($sql);
$row = mysql_fetch_assoc($record);

$fileName = $row['imageURL'];
$fileURL = 'images/products/' . $fileName;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header('Content-Disposition: attachment; filename=' . $row['imageURL']);
readfile($fileURL);
exit();

}

This should be working. Any problems?

  • 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-14T15:24:37+00:00Added an answer on June 14, 2026 at 3:24 pm

    As mentioned in the comments by Marc B, you can’t download a file through ajax. Ajax will just return the network request to the sender (i.e. jQuery ajax has a success handler function that contains the result of the request: http://api.jquery.com/jQuery.ajax/). One possible solution is to open a new window with the php url which will trigger the download request. A javascript solution is:

    window.open('dynamic-image-url.php');
    

    Another solution is using an anchor tag with the target=”_blank” attribute.

    <a href="dynamic-image-url.php" target="_blank">Download Image</a>
    

    The following is a php solution for returning an image taken from php’s readfile documentation:

    <?php
    $file = 'monkey.gif';
    
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
    ?>
    

    EDIT ** Added Form example which will post the variable

    <form action="dynamic-image.php" method="post" target="_blank">
       <input type="hidden" name="id" value="<?php echo $value; ?>" />
       <input type="submit" value="Download Image" />
    </form>
    

    You would then reference the variable as $_POST[‘id’] because that is the value of the name attribute in the form.

    Using a $_GET parameter, you would do it as below:

    <a href="dynamic-image-url.php?id=<?php echo $id; ?>" target="_blank">Download Image</a>
    

    Use $_GET[‘id’] to reference the value in PHP as id is the name of the query string parameter.

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

Sidebar

Related Questions

I'm using global variables to pass around a response from a AJAX call: window.response
I'm using a jQuery ajax call to get several entries from a large set
I have a dropdown in view that is using js I pass the selected
I have a field that is brought in via an AJAX call: <select id=selection>
I am using jquery's .post ajax call to pull an form input value and
I am using jQuery to call a php page (via ajax) that goes to
Is it possible to pass credentials using AJAX to a webserver that request www-authentication?
I am calling a php function using ajax call but its not working. I
I've a web page, where user can extend the session using AJAX call to
I am using an ajax call which is as follows var ID=$(this).attr('id'); var input=$(#input_+ID).val();

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.