How can I make a download page?

How would I make an admin only download page in php?

  • Is there any place to learn about making a secure admin page that lets me download my database into an excel file? For example, if I had an online survey and I saved the answers to the survey on the DB, instead of having an email being sent to me every time some one completes the survey. Someone could go to an admin page and download the DB in an excel format? The Excel form would have all of the Answered survey questions on it of course.

  • Answer:

    Why don't you try using google docs? You can create a form that can embed in your site, and have the responses submitted populate a google docs spreadsheet.

Stuart Starr at Quora Visit the source

Was this solution helpful to you?

Other answers

<?php     // Include the database file or connect to mySQL and select dabase here     include('database.php');      // Your SQL query     $sql = "Select * from table_name ";     $result = mysql_query($sql);     $sep = "\t"; //tabbed character     // Mention your filename and path where you have to store that excel file    $fp = fopen('../file_name.xls', "w");    $schema_insert = "";    $schema_insert_rows = "";     for ($i = 0; $i < mysql_num_fields($result); $i++)     {         $schema_insert_rows.=mysql_field_name($result,$i) . "\t";     }         $schema_insert_rows.="\n";         fwrite($fp, $schema_insert_rows);     //start while loop to get data     while($row = mysql_fetch_row($result))     {     //set_time_limit(60); //         $schema_insert = "";     for($j=0; $j<mysql_num_fields($result);$j++)     {         if(!isset($row[$j]))             $schema_insert .= "NULL".$sep;         elseif ($row[$j] != "")             $schema_insert .= strip_tags("$row[$j]").$sep;         else             $schema_insert .= "".$sep;     }     $schema_insert = str_replace($sep."$", "", $schema_insert);         //this corrects output in excel when table fields contain \n or \r        //these two characters are now replaced with a space             $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);         $schema_insert .= "\n";     //$schema_insert = (trim($schema_insert));     //print $schema_insert .= "\n";     //print "\n";             fwrite($fp, $schema_insert);     } fclose($fp); // Code here will allow you to download the the excel file of your database $filename = '../file_name.xls'; $ctype="application/[extension]"; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); // change, added quotes to allow spaces in filenames header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?>

Siddharth Vyas

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.