title: save excel file to server using php
body: <p>I am retrieving data from database and exporting it to excel with the below code, from this i can export to excel and saving the file from browser.</p>
  
  <pre><code>$sql_select= "my query";
  $queryRes = mysql_query($sql_select);
  
  $header = "Country" . "\t";
  $header .= "Network" . "\t";
  $header .= "MCC" . "\t";
  $header .= "MNC" . "\t";
  $header .= "ClientPrice" . "\t";
  $header .= "Currency" . "\t";
  
  $data = '';
  while( $row = mysql_fetch_assoc($queryRes)){
  $row1 = array();
  $row1[] = $row['country'];
  $row1[] = $row['networkname'];
  $row1[] = $row['mcc'];
  $row1[] = $row['mnc'];
  $row1[] = $row['clientprice'];
  $row1[] = $row['currency'];
  $data .= join("\t", $row1)."\n";
  //$data= $first_name."\t";
  //$data .= $row['originator']."\t";
  }
  
  header("Content-type: application/x-msdownload");
  header("Content-Disposition: attachment; filename=expot.xls");
  header("Pragma: no-cache");
  header("Expires: 0");
  print "$header\n$data"; 
  exit(); 
  </code></pre>
  
  <p>I am using the below code to save the excel file to this location "/pricelists/example.xls"</p>
  
  <pre><code>file_put_contents("/pricelists/example.xls",$data);
  print "$header\n$data";
  </code></pre>
  
  <p>It is showing warning</p>
  
  <pre><code>Warning: file_put_contents(/pricelists/example.xls) [function.file-put-contents]: failed to open stream:
  </code></pre>
  
  <p>Can anyone guide me how to fix this thanks?</p>