Jump to content

Question

Posted

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.

8 answers to this question

Recommended Posts

  • 0
Posted (edited)

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
  • 0
Posted

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>
	";

 

  • 0
Posted (edited)
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
  • 0
Posted

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
?>

 

  • 0
Posted
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

  • 0
Posted (edited)

 

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
  • 0
Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock