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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...