Help needed with why this is failing for me but not the

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Papabard
Forum Newbie
Posts: 2
Joined: Mon Apr 18, 2011 12:05 pm

Help needed with why this is failing for me but not the

Post by Papabard »

author

didn't write this as I have yet to find some good books on php programming that doesn't make the wife divorce me after my last book purchases

Anyway this code is claimed to be working for the person who wrote the app its in. What it does is lets me browse to the guild.xml file on my local machine then renames it randomly with a number. It fails any time I try to do it with a

[phpBB Debug] PHP Notice

: in file /roster/roster/roster-update.php on line 24: copy() [function.copy]: Filename cannot be empty
Error[phpBB Debug] PHP Notice: in file /roster/roster/roster-update.php on line 32: fopen(roster/uploads/5444guild.xml) [function.fopen]: failed to open stream: No such file or directory
could not open XML input

I simply need this dang thing to work and its driving me crazy. That snip can be rewritten as long as it allows for the next part of the script to work which is below it.

Code: Select all

 print '<table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr><th>Cleanup Successful. <a href="index.php?roster">Return to Roster</a></th></tr>
   </table>';
} elseif (isset($_POST['SubmitOne'])) {
   if ($_FILES['GuildData']['name'] == "guild.xml") {
      print '<table width="100%" border="0" cellpadding="0" cellspacing="0"><form enctype="multipart/form-data" method="POST">';
      $target_path = "roster/uploads/";
      $file_name = $_FILES['GuildData']['name'];
      $random_digit=rand(0000,9999);
      $new_file_name=$random_digit.$file_name;
      $path= "roster/uploads/".$new_file_name;
      if($GuildData !=none) {
         if(copy($_FILES['GuildData']['tmp_name'], $path)){
            print '<tr><th>Success: Roster Updated</th></tr>';
            print '<tr><td class="row1">The guild.xml has been successfully uploaded, and the roster updated.</td></tr>';
         } else {echo "Error";}
      }

The above fails

this is what needs to happen after the above suceeds.

      function GetElementByName ($xml, $start, $end) {global $pos; $startpos = strpos($xml, $start); if ($startpos === false) {return false;} $endpos = strpos($xml, $end); $endpos = $endpos+strlen($end); $pos = $endpos; $endpos = $endpos-$startpos; $endpos = $endpos - strlen($end); $tag = substr ($xml, $startpos, $endpos); $tag = substr ($tag, strlen($start)); return $tag;}
      $pos = 0; $Nodes = array();
      if (!($fp = fopen($path, 'r'))) {die("could not open XML input");}
      while ($getline = fread($fp, 4096)) {$data = $data . $getline;}
      $count = 0;
      $pos = 0;
      while ($node = GetElementByName($data, "<Member>", "</Member>")) {
         $Nodes[$count] = $node;
         $count++;
         $data = substr($data, $pos);
      }
Last edited by califdon on Mon Apr 18, 2011 1:00 pm, edited 1 time in total.
Reason: Moderator added syntax=php tags to make code readable. Note to poster, please always do this. Also deleted duplicate post.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: Help needed with why this is failing for me but not the

Post by fugix »

looks like your $_FILES['GuildData']['tmp_name'] var isn't passing any info..can i see the form that goes with this?
Papabard
Forum Newbie
Posts: 2
Joined: Mon Apr 18, 2011 12:05 pm

Re: Help needed with why this is failing for me but not the

Post by Papabard »

Here is the entire script.

I have also included an attachement of the entire package...


Code: Select all

<?php
if (!defined('IN_PHPBB')) {exit;}
if($user->data['is_registered']) {
	if ($user->data['group_id'] == $OfficerGroup1 || $user->data['group_id'] == $OfficerGroup2) {
if (isset($_POST['SubmitCleanup'])) {
	$arr1 = array("\\");
	$arr2 = array("");
	$cleaned = str_replace($arr1, $arr2, $_POST[CleanUpData]);
	mysql_query ("DELETE FROM evo_roster WHERE `CharName` <> 'A' ".$cleaned." ")
	or die(mysql_error());

	print '<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr><th>Cleanup Successful. <a href="index.php?roster">Return to Roster</a></th></tr>
	</table>';
} elseif (isset($_POST['SubmitOne'])) {
	if ($_FILES['GuildData']['name'] == "guild.xml") {
		print '<table width="100%" border="0" cellpadding="0" cellspacing="0"><form enctype="multipart/form-data" method="POST">';
		$target_path = "roster/uploads/";
		$file_name = $_FILES['GuildData']['name'];
		$random_digit=rand(0000,9999);
		$new_file_name=$random_digit.$file_name;
		$path= "roster/uploads/".$new_file_name;
		if($GuildData !=none) {
			if(copy($_FILES['GuildData']['tmp_name'], $path)){
				print '<tr><th>Success: Roster Updated</th></tr>';
				print '<tr><td class="row1">The guild.xml has been successfully uploaded, and the roster updated.</td></tr>';
			} else {echo "Error";}
		}

		function GetElementByName ($xml, $start, $end) {global $pos; $startpos = strpos($xml, $start); if ($startpos === false) {return false;} $endpos = strpos($xml, $end); $endpos = $endpos+strlen($end); $pos = $endpos; $endpos = $endpos-$startpos; $endpos = $endpos - strlen($end); $tag = substr ($xml, $startpos, $endpos); $tag = substr ($tag, strlen($start)); return $tag;}
		$pos = 0; $Nodes = array();
		if (!($fp = fopen($path, 'r'))) {die("could not open XML input");}
		while ($getline = fread($fp, 4096)) {$data = $data . $getline;}
		$count = 0;
		$pos = 0;
		while ($node = GetElementByName($data, "<Member>", "</Member>")) {
			$Nodes[$count] = $node;
			$count++;
			$data = substr($data, $pos);
		}
		$cleanup = '';
		for ($i=0; $i<$count; $i++) {
			$CharName = GetElementByName($Nodes[$i], "<Name>", "</Name>");
			$CharRank = GetElementByName($Nodes[$i], "<Rank>", "</Rank>");
			$CharLevel = GetElementByName($Nodes[$i], "<Level>", "</Level>");
			$CharClass = GetElementByName($Nodes[$i], "<Calling>", "</Calling>");

			mysql_query ("INSERT INTO evo_roster
			(`uid`, `username`, `CharName`, `CharLevel`, `CharRank`, `CharClass`, `CharSoul1Name`) VALUES
			('1', 'Unclaimed', '".$CharName."', '".$CharLevel."', '".$CharRank."', '".$CharClass."', 'Default Role')
			ON DUPLICATE KEY UPDATE `CharLevel`='".$CharLevel."', `CharRank`='".$CharRank."' ")
			or die(mysql_error());

			$cleanup .= "AND `CharName` <> '".$CharName."' ";
	}
	print '<tr><td class="row2">
	<input type="hidden" name="CleanUpData" value ="'.$cleanup.'">
	Would you like to cleanup any removed members from the roster now? <input type="submit" name="SubmitCleanup" value="Yes"></td></tr>';
	print'</form></table>';
	} else {
		print "Not guild.xml <br />";
	}
} else {
	print '
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<form enctype="multipart/form-data" method="POST">
			<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
			<tr><th>Instructions on Updating the Roster</th></tr>
			<tr><td class="row1">
			In order to update the guild roster, you need to do the following:
			<br />
				<ol>
					<li><strong><u>First Step</u></strong>: Log into the game, ona  character that is in the guild.</li>
					<li><strong><u>Second Step</u></strong>: Type /dumpguild</li>
					<li><strong><u>Third Step</u></strong>: Either log out, or tab out, of the game, go to this page, and click the "Choose File" button.</li>
					<li><strong><u>Next</u></strong>: Browse to your Rift install folder
						<ul>Default locations:
							<li><b>Windows 7/Vista/XP 32 Bit</b>: C:\Program Files\RIFT Game\</li>
							<li><b>Windows 7/Vista/XP 64 Bit</b>: C:\Program Files (x86)\RIFT Game\</li>
							<li><b>Steam Installs (32 bit)</b>: C:\Program Files\Steam\steamapps\common\rift</li>
							<li><b>Steam Installs (64 bit)</b>: C:\Program Files (x86)\Steam\steamapps\common\rift</li>
						</ul>
					</li>
					<li><strong><u>Finally</u></strong>: Select the guild.xml file, and click the "Upload Guild File" button.
				</ol>
				<br /><strong>You will need to do each step every time you want to update the roster.</strong>
			</td></tr>
			<tr><th>Select the guild.xml file</th></tr>
			<tr><td class="row2">Select the guild.xml file: <input name="GuildData" type="file"/></td></tr>
			<tr><td class="row2"><input type="submit" name="SubmitOne" value="Upload Guild File" /></td></tr>
		</form>
		</table>
	';
}
	} else {print "You must be an officer of the guild in order to view this page.";}
} else {print "You must be a registered member of the guild, and logged into the site, to view this page.";}
?>
Attachments
koreback.zip
(119.5 KiB) Downloaded 90 times
koreback.zip
(119.5 KiB) Downloaded 79 times
Post Reply