Skip to content

Php .doc file

Featured Replies

Hi, could someone help with .doc file saving to a website ftp. My code is only downloading it to my pc. Can't find any exaples in internet. I want that php would save it to a some folder and if file allready exist it would be reuploaded.

so you want to upload/rewrite a doc file on a ftp server thru a php script, which currently is downloading it to your pc instead?

 

can you post your code?

 

ps: r u using ftp_put()? it overwrites files by default, assuming you have correct permissions

Edited by sepultribe

  • Author

Yes, you are right. 

 

$host = ''; //Hosting
$user = ''; //Username
$pass = ''; //Password
$db = ''; //DatabaseName
$top = '100'; //Top Number
$countpvp = 1;
  try {
    $conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $conn->query("SET NAMES 'utf8'");
  }
  catch(PDOException  $e) {
    echo "Connection failed: " . $e->getMessage();
  }
  
	header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment;Filename=test.doc");

echo "	
		<table>
				<tr>
					<th align='left'>Name</th>
					<th align='right'>&nbsp;</th>
					<th align='right'>PvP</th>
				</tr>
	";
	
$pvp = "SELECT char_name, pvpkills FROM characters WHERE pvpkills > 0 AND accesslevel <= 0 ORDER by pvpkills DESC LIMIT $top ";
    $pvp = $conn->prepare($pvp);
    $pvp->execute();

    while($row = $pvp->fetch() ) {
      $countpvp++;

	echo
	"	
				<tr>
					<td align='left'><span>".$row['char_name']."</span></td>
					<td align='right'><span>&nbsp;</span></td>
					<td align='right'>".$row['pvpkills']."</td>
				</tr>
		
	";
	
}

echo "	
		</table>
	";

 

  • Author
33 minutes ago, sepultribe said:

so you want to upload/rewrite a doc file on a ftp server thru a php script, which currently is downloading it to your pc instead?

 

can you post your code?

 

ps: r u using ftp_put()? it overwrites files by default, assuming you have correct permissions

That doc file will be included in a website. So it could be saved in folder or next to a index.php

Edited by admirolas3

try this:

 

<?php
$host = ''; //Hosting
$user = ''; //Username
$pass = ''; //Password
$db = ''; //DatabaseName
$top = '100'; //Top Number
$countpvp = 1;
  try {
    $conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $conn->query("SET NAMES 'utf8'");
  }
  catch(PDOException  $e) {
    echo "Connection failed: " . $e->getMessage();
  }
  
	header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment;Filename=test.doc");
ob_start();
echo "	
		<table>
				<tr>
					<th align='left'>Name</th>
					<th align='right'>&nbsp;</th>
					<th align='right'>PvP</th>
				</tr>
	";
	
$pvp = "SELECT char_name, pvpkills FROM characters WHERE pvpkills > 0 AND accesslevel <= 0 ORDER by pvpkills DESC LIMIT $top ";
    $pvp = $conn->prepare($pvp);
    $pvp->execute();

    while($row = $pvp->fetch() ) {
      $countpvp++;

	echo
	"	
				<tr>
					<td align='left'><span>".$row['char_name']."</span></td>
					<td align='right'><span>&nbsp;</span></td>
					<td align='right'>".$row['pvpkills']."</td>
				</tr>
		
	";
	
}

echo "	
		</table>
	";
$out = ob_get_contents();
ob_end_clean();
echo $out;
file_put_contents("test.doc",$out); // this save doc to next to index.php
?>

 

  • Author
19 hours ago, wongerlt said:

try this:

 


<?php
$host = ''; //Hosting
$user = ''; //Username
$pass = ''; //Password
$db = ''; //DatabaseName
$top = '100'; //Top Number
$countpvp = 1;
  try {
    $conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $conn->query("SET NAMES 'utf8'");
  }
  catch(PDOException  $e) {
    echo "Connection failed: " . $e->getMessage();
  }
  
	header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment;Filename=test.doc");
ob_start();
echo "	
		<table>
				<tr>
					<th align='left'>Name</th>
					<th align='right'>&nbsp;</th>
					<th align='right'>PvP</th>
				</tr>
	";
	
$pvp = "SELECT char_name, pvpkills FROM characters WHERE pvpkills > 0 AND accesslevel <= 0 ORDER by pvpkills DESC LIMIT $top ";
    $pvp = $conn->prepare($pvp);
    $pvp->execute();

    while($row = $pvp->fetch() ) {
      $countpvp++;

	echo
	"	
				<tr>
					<td align='left'><span>".$row['char_name']."</span></td>
					<td align='right'><span>&nbsp;</span></td>
					<td align='right'>".$row['pvpkills']."</td>
				</tr>
		
	";
	
}

echo "	
		</table>
	";
$out = ob_get_contents();
ob_end_clean();
echo $out;
file_put_contents("test.doc",$out); // this save doc to next to index.php
?>

 

Shows an error :

 

Parse error: syntax error, unexpected 'ob_start' (T_STRING) in C:\xampp\htdocs\phptext.php on line 21

 

check file encode, with example notepad++ or php version, rly idk :D

or if u need just write result to file.

<?php
$host = ''; //Hosting
$user = ''; //Username
$pass = ''; //Password
$db = ''; //DatabaseName
$top = '100'; //Top Number
$countpvp = 1;
  try {
    $conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $conn->query("SET NAMES 'utf8'");
  }
  catch(PDOException  $e) {
    echo "Connection failed: " . $e->getMessage();
  }
  

$out = "	
		<table>
				<tr>
					<th align='left'>Name</th>
					<th align='right'>&nbsp;</th>
					<th align='right'>PvP</th>
				</tr>
	";
	
$pvp = "SELECT char_name, pvpkills FROM characters WHERE pvpkills > 0 AND accesslevel <= 0 ORDER by pvpkills DESC LIMIT $top ";
    $pvp = $conn->prepare($pvp);
    $pvp->execute();

    while($row = $pvp->fetch() ) {
      $countpvp++;

	$out .=
	"	
				<tr>
					<td align='left'><span>".$row['char_name']."</span></td>
					<td align='right'><span>&nbsp;</span></td>
					<td align='right'>".$row['pvpkills']."</td>
				</tr>
		
	";
	
}

$out .= "	
		</table>
	";
file_put_contents("test.doc",$out); // this save doc to next to index.php
?>

 

Edited by wongerlt

  • Author

Thanks, found what is wrong. Now i am searching for a time script. I need to get the current time in seconds or milliseconds, so that my script would be uploaded every x time.

use cronjobs

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.