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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:55:24+00:00 2026-05-26T23:55:24+00:00

I am working on a function for a PostgreSQL database, that when client issues

  • 0

I am working on a function for a PostgreSQL database, that when client issues a database dump, the dump is offered as a download. This snapshot could then later be used to restore the database with. However, I can’t seem to figure out how to do it. When the user presses the button, an AJAX call to the server is made, as to which the server executes the following code:

if($_POST['command'] == 'dump'){
    $dump = $table->Dump();
    header("Content-type: application/octet-stream");
    header('Content-Disposition: attachment; filename=/"'.$dump.'/"');
}

Where $table->Dump() looks like this:

public function Dump(){
    $filename = dirname(__FILE__)."/db_Dump.out";
    exec("pg_dump ".$this->name." > $filename");
    return $filename;
}

The dump isn’t made though. Any tips on this?

This approach however, doesn’t work. I thought that setting the headers would be enough to cause a download, but apparently I was wrong. So what would be the correct way of creating a download?


Edit 1, @stevevls:

if($_POST['command'] == 'dump'){
    $dump = $table->Dump();
    $fh = fopen($dump, 'r') or die("Can't open file");
    header("Content-type: application/octet-stream");
    header('Content-Disposition: attachment; filename=/"'.$dump.'/"');
    $dumpData = fread($fh, filesize($fh));
    fclose($fh);
    echo $dumpData;
}

I still don’t get anything as a download though.


Edit 2, @myself

I have been able to get a return value, it seemed that the the check if the command given was ‘dump’ was never reached. I fixed that, and now I get an error on the pg_dump command. I now get

sh: cannot create ../database/db_Dump.sql: Permission denied

I bet this is due to php not being allowed to run pg_dump, but how could I get the system to allow it to be able to run it?


Edit 3, @myself

After resolving the issue with the pg__dump (I added www-data, Apaches user on my system, to the sudoers list, which resoved the issue. Also setting the correct permissions on the directory to write to is handy aswell.) I now get the db_Dump.sql as plain text instead of a save as dialog. Any ideas on that?

  • 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-26T23:55:24+00:00Added an answer on May 26, 2026 at 11:55 pm

    Turns out, it was all due to the fact of how I requested the download. It seems that it is impossible to get a download when you request it via Ajax, as the returned file get’s accepted in the success method of the call. After Changing this to a direct link to the file, I was able to get a download.

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

Sidebar

Related Questions

I am having issues getting my remove element function working. I have this function:
I have this working function that finds folders and creates an array. function dua_get_files($path)
the second function isnt working? $('.edit_hover').live('hover', function(e){ $(this).stop(); var half_width = ($(this).css('width').slice(0, -2))/2; var
I was just working on a function that I needed to return two values,
Does anyone have a working class or function to create the hashed email that
i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
I am trying to make this function that extracts text from html for multiple
I'm currently working on a simple banking application. I have built a postgresql database,
im using DBI in Perl to connect to my PostgreSQL Database. Everything is working
I've got the following code that I can't seem to get working: function drawTable($result)

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.