hane Posted June 18, 2010 Share Posted June 18, 2010 Hi for some reason I just cant get my code to work. Please take a look and help me in the right direction. Here is my header builder for my export doc, $vExcelFileName is my problem: <?php require_once('includes/connect.php'); $adid=$_GET['adid']; mysql_select_db($database_A, $A); $query_ads = "SELECT * FROM ads JOIN company ON ads.companyid=company.companyid JOIN contact ON contact.companyid=ads.companyid WHERE adid=$adid"; $ads = mysql_query($query_ads, $A) or die(mysql_error()); $row_ads = mysql_fetch_assoc($ads); $totalRows_ads = mysql_num_rows($ads); $vExcelFileName=$row_ads['name'] . "ad-description-" . $row_ads['month'] ."-10" . ".doc"; header("Content-type: application/x-ms-download"); //#-- build header to download the excel file header("Content-Disposition: attachment; filename=$vExcelFileName"); header('Cache-Control: public'); ?> I'm sure its something silly that I'm not seeing and just need someone else to point it out Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/ Share on other sites More sharing options...
phpchamps Posted June 18, 2010 Share Posted June 18, 2010 whats the exact problem??? if you are not getting variable value.. try something like this header("Content-Disposition: attachment; filename=\"$outname\";\n\n"); Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073801 Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 I have checked the code and it works, but when a name has spaces it falls apart how can I fix that Here is the problem: $vExcelFileName=$row_ads['name'] . "ad-description-" . $row_ads['month'] ."-10" . ".doc"; Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073802 Share on other sites More sharing options...
phpchamps Posted June 18, 2010 Share Posted June 18, 2010 i run the code and its working fine at my machine.. even though... it has spaces in name... Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073805 Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 When I run the code for Company lets say AIP Africa for June the file name is supposed to be: aipafrica-ad-description-jun-10.doc what I get is AIP Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073808 Share on other sites More sharing options...
phpchamps Posted June 18, 2010 Share Posted June 18, 2010 and whts the filename do you get in that case???? Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073809 Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 what I get is AIP Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073810 Share on other sites More sharing options...
phpchamps Posted June 18, 2010 Share Posted June 18, 2010 are you sure your query is not returning multiple rows????? please post the result of your query.. Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073811 Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 remember i call the info from my mysql database so I select AIP Africa from drop down then I select export and it exports all the info to a .doc file with the name populated with my the script in question Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073812 Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 the easies would be to show you Go to http://www.hefty.co.za/agrisales/ Select Excaload from drop down submit then select PDF to see working example Select AIP Africa from drop down submit then select PDF to see problem Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073818 Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 I fixed it with urlencode. Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073834 Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 Please tell me if there is a better way Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073835 Share on other sites More sharing options...
hane Posted June 18, 2010 Author Share Posted June 18, 2010 Think I found a better way: $n= $row_ads['name']; $na= preg_replace('/\s*/m','',$n); $vExcelFileName= $na ."-ad-description-" . $row_ads['month'] . "-10" . ".doc"; Link to comment https://forums.phpfreaks.com/topic/205146-help-with-building-the-file-name-for-export-doc/#findComment-1073837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.