Jump to content

pls help...error in creating txt and pdf files on server for download


Oliverkahn

Recommended Posts

when i try it on my server it create file with the name "0" instead of "testopic.php"...

and display the text content as plane text instead of allowing me download the text in pdf and txt

here is the code the txtdownload.php contains ..

 

<?PHP
$topic =  "testtopic";
$topics = $topic + ".txt";
$msgg = "here goes the content";
$file_handle = fopen($topics , "w");
$file_contents = $msgg;
fwrite($file_handle, $file_contents);
fclose($file_handle);
print "<a href='$topics'>download thread in txt</a>" ;
?>
the pdfdownload.php contains the following code

<?PHP
$topic = "testtopic";
$topics = $topic + ".pdf";
$msgg = "content goes here";
$file_handle = fopen($topics , "w");
$file_contents = $msgg;
fwrite($file_handle, $file_contents);
fclose($file_handle);
print "<a href='$topics'>download thread in pdf</a>" ;
?>
thanks in advance...

This statement:

$topics = $topic + ".txt";

is using a mathematical plus operator. In doing so, PHP must convert the strings to their mathematical equivalent - which is the value zero.

 

To 'concatenate' (put strings together), please use the period:

$topics = $topic . ".txt";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.