steve012345 Posted June 2, 2008 Share Posted June 2, 2008 I have got this code which allows me to download an excel file containing a dump of my studentanswerunit table which works fine when running on my localhost server. When using this code on my remote server however i get the error message "can't open file". <?php session_start(); error_reporting(0); if(isset($_SESSION['user'])==""){ require('userlogin.php'); exit(); } include "config.php"; $myFile = "test.xls"; $querystring = "SELECT * FROM `studentanswerunit`"; $mysqlquery = mysql_query($querystring); $myData = "<table width=\"100%\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" border=\"1\"> <tr bgcolor=#cccccc><td align=center><b>Student No</b></td><td align=center><b>Unit Id</b></td><td align=center><b>Question Id</b></td><td align=center><b>Answer</b></td></tr>"; while($row = mysql_fetch_array($mysqlquery)) { $myData .= ' <tr> <td align=center>'.$row[studentno].'</td><td align=center>'.$row[unitid].'</td><td align=center>'.$row[questionid].'</td><td align=center>'.$row[answer].'</td> </tr>'; } $myDate .= "</table>"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $myData; fwrite($fh, $stringData); fclose($fh); $file="test.xls"; if (file_exists($file)): header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment;filename=".$file ); header('Pragma: no-cache'); header('Expires: 0'); readfile($file); endif; ?> I have tried various paths, different path formats but nothing seems to be working. the file is located with all the other web page files. Is this the wrong location then where is the right one and how do I code that path in php. Please help! Link to comment https://forums.phpfreaks.com/topic/108459-using-excel-files-on-localhost-works-ok-but-not-on-remote-server/ Share on other sites More sharing options...
discomatt Posted June 2, 2008 Share Posted June 2, 2008 Your remote server may have disabled allow_url_fopen Link to comment https://forums.phpfreaks.com/topic/108459-using-excel-files-on-localhost-works-ok-but-not-on-remote-server/#findComment-556089 Share on other sites More sharing options...
steve012345 Posted June 2, 2008 Author Share Posted June 2, 2008 do you know how i can check this? Also anyway around this? Link to comment https://forums.phpfreaks.com/topic/108459-using-excel-files-on-localhost-works-ok-but-not-on-remote-server/#findComment-556091 Share on other sites More sharing options...
steve012345 Posted June 3, 2008 Author Share Posted June 3, 2008 ok basically i have now got a table displaying in my browser rather than an excel file download. It appeared I just had the wrong path set. ideally I want this file to automatically download as it does on my localhost with the same code and not show in the browser. any help? Link to comment https://forums.phpfreaks.com/topic/108459-using-excel-files-on-localhost-works-ok-but-not-on-remote-server/#findComment-556113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.