PHP - Export To Excel Not Work From Pc Client But Work In Server.
Hi..,
I use below method to export data to excel. header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename=abc.xls'); if I run the script from the server. (http://localhost/export.php) it is work. (pop-up window if i want save or open the file) but if i run the script from the client (http://192.168.1.5/export.php) it is not work. (nothing happen) any idea how to solve this? Similar TutorialsI wish to create validation rules once which are used both on the client and on the server.
For instance, I will start off with the following PHP object:
stdClass Object ( [rules] => stdClass Object ( [email] => stdClass Object ( [required] => 1 [email] => 1 [remote] => stdClass Object ( [url] => check-email.php [type] => post [data] => stdClass Object ( [username] => function() {return $( '#username' ).val();} ) ) ) ) [messages] => stdClass Object ( [email] => stdClass Object ( [required] => an email is required ) ) )When the edit page is downloaded to the client, I will include this object in some format suitable to the client. The client will then use the jQuery Validation plugin (http://jqueryvalidation.org/) along with the validation object, and client side validate the page. When the form passes client side validation and is uploaded, PHP will use the same validation object to serverside validate the form (I have this part working as desired). My question is how should I pass this data to the client? Originally, I would just use PHP to write some JavaScript. exit('var myObj='.json_encode($myObj));Note that when I json_encode the object, the value of $myObj->rules->email->remote->data->username is a string with quotes around it, however, I can easily use PHP to strip these tags before sending it to the client. As Jacques1 pointed out in http://forums.phpfre...ascript-client/, I should never ever use PHP to generate JavaScript, and should use AJAX to download the JSON directly. I tried doing the later, but found that a callback function could not be included in the JSON. Please advise on the best way to accomplish this. Thank you Hi I have a page displaying orders from a mysql table. How can i add a button which exports this to an excel file? ok, so I am not good with arrays, they confuse me. how can I set this up so that $data is all results that are returned from the database that correspond to it? Code: [Select] $data = array( array("firstname" => '$firstname', "lastname" => '$lastname', "age" => '$age')); the original code looked like: Code: [Select] <?PHP $data = array( array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25), array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18), array("firstname" => "James", "lastname" => "Brown", "age" => 31), array("firstname" => "Patricia", "lastname" => "Williams", "age" => 7), array("firstname" => "Michael", "lastname" => "Davis", "age" => 43), array("firstname" => "Sarah", "lastname" => "Miller", "age" => 24), array("firstname" => "Patrick", "lastname" => "Miller", "age" => 27) ); ?> but that won't do it for me. I need it so that the results from the database will automatically be filled in. basically, everyone that is in the database, so when a new member is added, they will show up too. please help Is it possible to export a single value from a mysql DB into a pre-existing excel spread sheet? I know how to create a spread sheet from php and mysql, but not a single value into a pre-existing excel document cell. here's basically what I'm doing: Creating a financial expense tracking report in php, user will input each expense, it will keep a running tally of the available funds in user's bank account. The user has an excel spread sheet that requires the current value of available funds and updates a budget forecast according. SO, I need to somehow get the available balance of the bank account (generated by user input) into the pre-existing excel spreadsheet. Any thoughts? I'm totally at a loss. Thanks! HI Gurus, I need to export (download) a csv file from the web server to my client. How can this be done in php ? How is the save as dialog invoked ? (I am assuming that file save permissions are allowed) I read that if you invoke the following script (eg form submit), it will work .. <? header("Content-type: text/plain"); header("Content-Disposition: attachment; filename=YOUR_FILE.csv"); ?> Any advice ? Steven M So i have this script, it pull data via mysql and inserts it into an excel file. However it does not properly tab each field as it should nor go to a new lines as it should instead it stick everything into 1 whole row. Ok but here's the kicker... this same identical script runs 100% fine on another website. The only difference is the query string. There it works fine on this new site it bugs out. any idea where the bug is? <?php include('dbcon.php'); $tablename = $_POST['tablename']; $full_query = "SELECT * FROM $tablename"; $header = ''; $data = ''; $export = mysql_query($full_query); $fields = mysql_num_fields($export); for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . "\t"; } while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); if ($data == "") { $data = "\n(0) Records Found!\n"; } header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=monet_search_results.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; ?> PS: This is a linux box if that makes a difference. THANKS! am using this code Code: [Select] <?php require_once 'PHPExcel.php'; require_once 'PHPExcel/IOFactory.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("Matthew Casperson") ->setLastModifiedBy("Matthew Casperson") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes."); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', 'Hello') ->setCellValue('B2', 'world!') ->setCellValue('C1', 'Hello') ->setCellValue('D2', 'world!'); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="test.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); ?> but excelsheet contain following error............. <b>Fatal error</b>: Class 'ZipArchive' not found in <b>C:\Program Files\xampp\htdocs\immigration\PHPExcelSourceCode\PHPExcel\Writer\Excel2007.php</b> on line <b>224</b><br /> but excelsheet contain this error............. please help how to fix it? im trying to connect to our office server by remote desktop.. but when i do it..alot of error came out from my index.php and counter.php.. does anyone ever experience these problems? what should i do.. Have a strange problem on a new server that we've migrated to. I use class.phpmailer extensively with no problems but since moving to the new one, i notice that emails sent to ids on the same domain as the sender just dont go thru . i cannot figure out why this could be happening. What could i do to resolve this problem please? Thanks: Swati. OLD SERVER : PHP 2.6.4 , MYSQL - 4.1.12 NEW SERVER PHP 3.2.4 , MYSQL 5.1.50 My code snippet <? if($_POST['submit']){ $dec = $_POST["dec"]; require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsMail(); $mail->From = "form@exam.com"; $mail->FromName = "exam"; if ($dec == "on"){ $mail->AddAddress("dec@exam.com"); // doesnt go thru $mail->AddAddress("dec@anyother.com"); // goes thru // add it } } ?> Hi all, I am a newbie to PHP. I'm trying to execute a program from my PHP script by calling the exec() function of PHP. It works fine when i try it from command line, or execute the script in command line. But when i call it from a php script in my apache, it does nothing. No errors are thrown. What i get in return is only an empty array. i'm using Ubuntu 11.10 and Apache 2.2 with PHP 5.3.3 thanks for helping me. Hello, im using a contact form which sends me an email with the data name.. comments .. Now im testing a new better server which use IMAP (old POP3) and my form is not working like it used to be.. Code: [Select] $emailTo = " $dbSentEmail"; //Put your own email address here $emailServer = "noreply@totalsports.com.cy"; //Put your own email address here $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n"; $headers .= 'From: Contact Form <'.$emailServer.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); Any idea what i have to do to work like before? Hello, I want to export data from php-mysql to excel in a particular cell. 1. Get the data from php-Mysql and export data to excel sheet. I already create a template excel sheet format.I want to export data from mysql to a particular cell. Sorry I can't able to attach my template excel sheet. 2. Is it possible to export image? Thanks in advance Hi All, I am exporting data to excel, but run into a problem if the text contains a line break. When it gets to the line break, it cuts off the rest of the text. Here is my printer code: Code: [Select] $file = 'Notes_Export'; $csv_output = array(); $tmp = array(); $tmp[] = 'Created On'; $tmp[] = 'Created By'; $tmp[] = 'Note'; $csv_output[] = '"' . implode('","', $tmp) . '"'; $sql = "SELECT pn.created_on, CONCAT( u.firstname,' ', u.lastname) AS created_by, pn.note FROM prop_notes pn LEFT JOIN users u ON pn.created_by = u.user_id "; $sql .= "WHERE pn.deleted_by IS NULL AND pn.archive = '0' AND pn.property_id = '".$_GET['pid']."'"; $result = mysqli_query($connect, $sql); while($rowr = mysqli_fetch_row($result)) { $tmp = array(); for ($j=0; $j<3; $j++) {$tmp[] = $rowr[$j];} $csv_output[] = '"' . implode('","', $tmp) . '"'; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); // header( "Content-disposition: filename=".$filename.".csv"); header("Content-disposition: attachment; filename=".$filename.".csv"); print implode("\n",$csv_output) . "\n"; exit; I am a newbie to this forum and a real beginner on PHP
After the website went down after the server upgrade to 5.4.30, parts came back but in other places got 2 error messages.
1. Home page - Login by members
Fatal Error: call to undefined function session_is_registered() in member_auth_fns.php on line 28
2. Admin - Login by me
Parse error: syntax error, unexpected '$_SESSION' (T_VARIABLE), expecting '(' in contacts/user_auth_fns.php line 28
I appreciate that the old php was based on session_start (), session_register, session_is_registered, session_unregister, but these were all deprecated in 5.4.30.
So to put it bluntly, after trying to interpret the help manuals etc I found a backup I had taken before this and in respect of the Home page login and the admin login what I think was the previous relevant code was before the event
<?
function login ($member_name, $password)
// check member and password with db
// if yes, return true
//else return false
{
// connect to db
$conn = db_connect();
if (!$conn) return 0;
$result = MySQL_query(select * from people
where username='$member_name'
and password = '$password' ");
if (!$result) return 0;
if (MySQL_num_rows($result)>0)
return 1;
else
return;
}
function check_auth_member
Some text here
global $auth_member;
if ( (session_is_registered("auth_member")) && (isset($auth_member)) )
return true;
else
return false
}
?>
Anyone who can give me the revised code for this it would be greatly appreciated
Learner
Hello, I have a call tu function unserialize() in a script that receives a string and has to return an array. In my localhost it works properly but in the server it returns a 1 dimension array with empty value. I'm testing with the string a:1:{s:1:"0";s:8:"value_eq";} The php.ini configuration for magic_quotes is (in both, server and localhost): magic_quotes_gpc Off magic_quotes_runtime Off Other configurations is difficult to compare, as php info is long and very different in local and server. Any ideas where the problem might be? Thank you if(isset($_POST['clearflags'])){ $output = shell_exec('php clearflags.php'); } The above works fine on my local development server running Debian 10, PHP 7.4 and Apache 2.4.25. clearflags.php is a script that clears various fields in a MySQL database so it's easy to determine if it properly ran or not. On my hosted server however (Bluehost), clearflags.php is never executed. My hosting service swears that SAFE MODE is not on in PHP (which is also Version 7.4). If I call from the command line (php clearflags.php), it runs fine. $output on the hosted server is "Content-type: text/html; charset=UTF-8 " but nothing on my local server where the script is called and runs OK. No entry appears in the error log about this I've also tried using exec() with the same failed result Running phpinfo() on the hosted server shows that disabled_functions are "no value" Thoughts? Edited October 11, 2020 by KenHorseSo I have a big table of about 30-40 columns. Some variables are quite long strings while others are simple tinyint(1) values.
Input into the code is a value or range of values or something that applies to each of the columns.
I need to find which ones are an applicable match to the user request and then load them into php.
Now I know variations can cause something to run more optimally one way or another but this system will get bogged down with lots of requests and lots of data, so any additional performance I give it now will help me down the road. I am just looking for general concepts to help, not specific code tweaking.
I have heard the typical rule is to query mysql as little as possible and do the hard lifting in php but I am not positive this is right.
Since I have to query anyways, should I do a mysql pull using a complex 'WHERE' to do most of the sorting. ie only get rows where a=1, b>5, c="http://google.com", d="3242342323kj4238237489023ejfjf3jrjf8jeifjdjf" ie long string, etc for all 30+columns?
OR I pull the whole DB and do all the sorting in php...
OR I do all the simple sorting in the MySQL query and some of the more complicated sorting in PHP (or vice versa)
Any ideas would help.
I implemented google's reCAPTCHA V2 on http:// on the remote apache shared server and it worked 100%. I then changed the protocol to my shared server SSL using the same PHP script as the non-SSL script. The older version of reCaptcha had an SSL 'false' to 'true' SSL parameter, whereas I can't find one for V2. I had to use htaccess to redirect the example.com to the shared SSL server https://serverid.net/example/ which works perfectly without recCAPTCHA. I incorporated reCAPTCHA V2 and the error message where the reCAPTCHA image should be shows "ERROR: Invalid domain for site key". Hi All, As we know........to export excel sheet the database content....we query the data base and then process the result and using Workbook and header we export the result in excel.................. Is there any way we can reduce the down load time or increase the performance for same. ? Thanks. |