Jump to content

Need this Upload Form to Generate a URL


Mesden

Recommended Posts

This is kind of difficult to explain so bare with me. I have a Starcraft II Replay Parser on my website which doesn't require Registration to parse the Replay File. http://www.sc2x.net/upload_file.phpAt the moment, when the user uploads his/her Replay and clicks Submit, it shows the Patch, the Build, the Team Size, the Game Speed, the Players, their Race, their Color, and the entire Chat Log. This is all correctly accurate information but it's not where I want it to be.Think YouTube for example, when you upload a video, it doesn't display the video on the upload page when it's completed, it generates a seperate page/url for the video. That's exactly what I need it to do here. I need it to generate a different page and display the results there. How would I do that? (Bare in mind I am not that good at PHP so you might need to dum things down.)Here's the coding if it helps:

<?phpfunction createAPMImage($vals, $length, $fn) {		$width = 300;		$height = 200;		$pixelsPerSecond = $width/ $length;		$pic = imagecreatetruecolor($width,$height);		$lineColor = imagecolorallocate($pic,0,0,0);		$lineColorGrey = imagecolorallocate($pic,192,192,192);		$bgColor = imagecolorallocate($pic,255,255,255);		$bgColorT = imagecolorallocatealpha($pic,255,255,255,127);		imagefill($pic,0,0,$bgColorT);		// first create x/y pairs		$xypair = array();		$maxapm = 0;		for ($x = 1;$x <= $width;$x++) {				$secs = ceil($x / $pixelsPerSecond);				$apm = 0;				if ($secs < 60) {						for ($tmp = 0;$tmp < $secs;$tmp++)								$apm += $vals[$tmp];						$apm = $apm / $secs * 60;				} else {						for ($tmp = $secs - 60;$tmp < $secs;$tmp++)								$apm += $vals[$tmp];						$apm = $apm;				}				if ($apm > $maxapm)						$maxapm = $apm;				$xypair[$x] = $apm;		}		// then draw them		if ($maxapm == 0)				return;		for ($i = 2;$i <= $width;$i++) {				imageline($pic,$i - 1,$xypair[$i - 1] / $maxapm * $height, $i, $xypair[$i] / $maxapm * $height,$lineColor);		}		$frame = imagecreatetruecolor($width +50,$height+50);		imagefill($frame,0,0,$bgColor);				imagerectangle($frame,40,0,$width + 40,$height,$lineColor);		imageline($frame,40,$height / 2,$width + 40,$height / 2, $lineColorGrey);		imagestringup($frame,4,5,$height - 15,"APM -->",$lineColor);		imagestring($frame,4,55,$height + 20,"Time (minutes)",$lineColor);		imagestring($frame,2,25,$height - 15,"0",$lineColor);		imagestring($frame,2,20,($height / 2),floor($maxapm / 2),$lineColor);		imagestring($frame,2,20,0,floor($maxapm),$lineColor);		$lengthMins = ($length / 60);		for ($i = 0;$i < $lengthMins;$i+=5) {				imagestring($frame,2,40+($width / ($lengthMins / 5) * ($i / 5)),$height + 5,$i,$lineColor);				if ($i > 0)						imageline($frame,40+($width / ($lengthMins / 5) * ($i / 5)),0,40+($width / ($lengthMins / 5) * ($i / 5)),$height, $lineColorGrey);			  		}		imagecopy($frame,$pic,40,0,0,0,$width,$height);		imagepng($frame,$fn);		imagedestroy($frame);		imagedestroy($pic);}$MAX_FILE_SIZE = 1000000;if (isset($_FILES['userfile'])) {		$error = $_FILES['userfile']['error'];		$type = $_FILES['userfile']['type'];		$name = $_FILES['userfile']['name'];		$tmpname = $_FILES['userfile']['tmp_name'];		$size = $_FILES['userfile']['size'];		$err = false;		if ($size >= $MAX_FILE_SIZE) {				echo "Error: File is too large. Replay File must be below 1MB.<br />";				$err = true;		}		if ($error == UPLOAD_ERR_PARTIAL) {				echo "Error: The upload was not completed successfully. Please try again.<br />";				$err = true;		}		if ($error == UPLOAD_ERR_NO_FILE) {				echo "Error: Please select a File to upload.<br />";				$err = true;		}		if (!is_uploaded_file($tmpname)) {				echo "Error: Uploaded filename doesn't point to an uploaded file.<br />";				$err = true;		}		if ($err !== true) {				if (class_exists("MPQFile") || (include 'mpqfile.php')) {						$start = microtime_float();						if ($_POST['debug'] == 1) {								echo sprintf("<b>Debugging is on.</b><br />\n");						}						$a = new MPQFile($tmpname,true,(($_POST['debug'] == 1)?2:0));						$init = $a->getState();						if ($init == MPQ_ERR_NOTMPQFILE)								echo "Could not parse the Replay. Check to make sure it's a valid .SC2Replay File.<br />\n";						else if ($a->getVersion() < 9)								echo "Error: Invalid Version.<br />\n";						else {								echo sprintf("Major version %d, build %d<br />\n",$a->getVersion(),$a->getBuild());								$b = $a->parseReplay();								$tmp = $b->getPlayers();								echo sprintf("Map name: %s, Game length: %s<br />\n",$b->getMapName(),$b->getFormattedGameLength());								echo sprintf("Team size: %s, Game speed: %s<br />\n",$b->getTeamSize(), $b->getGameSpeedText());																$apmString = "<b>APM graphs</b><br />\n";								echo "<table border=\"1\"><tr><th>Player name</th><th>Long name</th><th>Race</th><th>Color</th><th>Team</th><th>Average APM<br />(experimental)</th><th>Winner?</th></tr>\n";								foreach($tmp as $value) {										$wincolor = ($value['won'] == 1)?0x00FF00:0xFF0000;										echo sprintf("<tr><td>%s</td><td>%s</td><td>%s</td><td><font color=\"#%s\">%s</font></td><td>%s</td><td style=\"text-align: center\">%d</td><td style=\"background-color: #%06X; text-align: center\">%d</td></tr>\n",																		$value['sName'],																		$value['lName'],																		$value['race'],																		$value['color'],																		$value['sColor'],																		($value['party'] > 0)?"Team ".$value['party']:"-",																		($value['party'] > 0)?(round($value['apmtotal'] / ($b->getGameLength() / 60))):0,																		((isset($value['won']))?$wincolor:0xFFFFFF),																		(isset($value['won']))?$value['won']:(($value['party'] > 0)?"Unknown":"-")																);										if ($value['party'] > 0) {												$apmFileName = $value['id']."_".md5($name).".png";												createAPMImage($value['apm'],$b->getGameLength(),$apmFileName);												$apmString .= sprintf("%s:<br /><img src=\"$apmFileName\" /><br />\n",$value['sName']);										}								}								echo "</table><br />";								$messages = $b->getMessages();								if (count($messages) > 0) {										echo "<b>Messages:</b><br /><table border=\"1\"><tr><th>Time</th><th>Player</th><th>Target</th><th>Message</th></tr>\n";										foreach ($messages as $val)												echo sprintf("<tr><td>%d sec</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",$val['time'],																		  $val['name'], ($val['target'] == 2)?"Alliance":"All",$val['message']);										echo "</table><br />\n";								}								echo $apmString;																$t = $b->getEvents();								if (isset($sc2_abilityCodes) || (include 'abilitycodes.php')) {										echo "<table border=\"1\"><tr><th>Timecode</th>\n";										$pNum = count($tmp);										foreach ($tmp as $value) {										  if ($value['party'] > 0)												echo sprintf("<th>%s (%s)</th>",$value['sName'],$value['race']);										}										echo "</tr>\n";										foreach ($t as $value) {												echo sprintf("<tr><td>%d sec</td>",$value['t'] / 16);												foreach ($tmp as $value2) {														if ($value2['party'] == 0) continue;														if ($value['p'] == $value2['id'])																echo sprintf("<td>%s</td>",$b->getAbilityString($value['a']));														else																echo "<td></td>";												}												echo "</tr>\n";										}										echo "</table>";								}						}						$end =  microtime_float();						echo sprintf("Time to parse: %d ms.<br />\n",(($end - $start)*1000));				}		}}?>

Link to comment
Share on other sites

  • Replies 79
  • Created
  • Last Reply

Instead of displaying the results, you need to either:1. Store them in a database, and then constuct pages accordingly via a separate viewing script (to which you may redirect at upload time).2. Create new files that the users will then be able to access (and to which you can redirect once they're created).The second option is probably easier to do, but if you decide to reorganize your files, those files might make it harder for you. So, if you aren't already familiar with MySQL, it's probably about time you start.

Link to comment
Share on other sites

Instead of displaying the results, you need to either:1. Store them in a database, and then constuct pages accordingly via a separate viewing script (to which you may redirect at upload time).2. Create new files that the users will then be able to access (and to which you can redirect once they're created).The second option is probably easier to do, but if you decide to reorganize your files, those files might make it harder for you. So, if you aren't already familiar with MySQL, it's probably about time you start.
I'm familiar with creating a Database in my web server's control panel. Just not the coding aspect of it. I wouldn't even begin to comprehend where to begin though... I guess step one is making the upload form generate a blank page with the parser results on it? (At which point I can then start telling it to put content on there as well?)How would I do that..?
Link to comment
Share on other sites

I'd say step one is creating your DB (with your control panel if you have to). The only table you need to add in your DB is one which contains the different pieces of information as fields, plus an ID.Step two is to put some phony data for testing's sake, and try to output it on a separate page that only receives the ID as part of the URL.If you do that, to make it all happen you need to only insert the uploaded data into the DB, get the ID of the new row, and use the header function to redirect to the viewer, with the gathered ID as part of the URL.

Link to comment
Share on other sites

I'd say step one is creating your DB (with your control panel if you have to). The only table you need to add in your DB is one which contains the different pieces of information as fields, plus an ID.Step two is to put some phony data for testing's sake, and try to output it on a separate page that only receives the ID as part of the URL.If you do that, to make it all happen you need to only insert the uploaded data into the DB, get the ID of the new row, and use the header function to redirect to the viewer, with the gathered ID as part of the URL.
Okay I've created a Database in my MySQL Control Panel called Aaron21_Upload, as well as a DBA User with a password associated with it. I also have the Host Name and the Port Number. I'm presuming my next step is to add a table in phpMyAdmin. I know how to add a Table in phpMyAdmin, but I don't know what kind of table I need to add. You specified it just needs to be one table, but I don't know what information needs to be in that table.
Link to comment
Share on other sites

Like I said - The different pieces of information (from the SC2Replay file; the ones you can read with the parser), plus an ID field. Most of them will probably need a field of type VARCHAR (a string of varying size), but if another type fits the data more appropriately, you should use it instead.Each column (field) of the table will represent the kind of thing you've read, and each row (record) in the table will represent data for each file.

Link to comment
Share on other sites

Like I said - The different pieces of information (from the SC2Replay file; the ones you can read with the parser), plus an ID field. Most of them will probably need a field of type VARCHAR (a string of varying size), but if another type fits the data more appropriately, you should use it instead.Each column (field) of the table will represent the kind of thing you've read, and each row (record) in the table will represent data for each file.
Well each SC2 Replay File holds different information. Nothing will ever be the same. =/
Link to comment
Share on other sites

Wha...? Doesn't every SC2Replay contain

Patch, the Build, the Team Size, the Game Speed, the Players, their Race, their Color, and the entire Chat Log
?Yes, every time the actual data is different (obviously), but the kind of information is always the same, isn't it?If some things can be omitted, you can make those fields nullable (i.e. it may contain the value "null", indicating that such information was not present in the SC2Replay file). Still, for every piece of data you may want to show, you need a field.
Link to comment
Share on other sites

Wha...? Doesn't every SC2Replay contain?Yes, every time the actual data is different (obviously), but the kind of information is always the same, isn't it?If some things can be omitted, you can make those fields nullable (i.e. it may contain the value "null", indicating that such information was not present in the SC2Replay file). Still, for every piece of data you may want to show, you need a field.
Alright, so where would I fetch that data? I can't take it out of the SC2 Replay File without parsing it. Am I to assume that the PHP Coding that parses the file is what I use in the phpMyAdmin Table?
Link to comment
Share on other sites

Alright, so where would I fetch that data? I can't take it out of the SC2 Replay File without parsing it. Am I to assume that the PHP Coding that parses the file is what I use in the phpMyAdmin Table?
The whole idea of the parser is to read the data for you, so that you can then do whatever you want with it. Methods like "getPlayers()" let you easily see the number of players for example... You're currently just echoing it all, but you may instead construct a query that contains it, write a file that contains it... essentially, you can "[insert anything] that contains it"...You need to write a MySQL query (Yes... code... sorry... no way around it this time) that contains the data from the parser. And more precisely, a query that will insert it in the table. See the PHP MySQL Insert part of the tutorial if you don't know the syntax.
Link to comment
Share on other sites

The whole idea of the parser is to read the data for you, so that you can then do whatever you want with it. Methods like "getPlayers()" let you easily see the number of players for example... You're currently just echoing it all, but you may instead construct a query that contains it, write a file that contains it... essentially, you can "[insert anything] that contains it"...You need to write a MySQL query (Yes... code... sorry... no way around it this time) that contains the data from the parser. And more precisely, a query that will insert it in the table. See the PHP MySQL Insert part of the tutorial if you don't know the syntax.
These are all the Parseables:
Player name	 getPlayers(),array index 'sname'	 replay.details,replay.attributes.eventsPlayer race	 getPlayers(),array index 'race'	 replay.details,replay.attributes.eventsPlayer color(text)	 getPlayers(),array index 'scolor'	 replay.attributes.eventsPlayer color(rgb)	 getPlayers(),array index 'color'	 replay.detailsPlayer team	 getPlayers(),array index 'party'	 replay.detailsPlayer handicap	 getPlayers(),array index 'handicap'	 replay.attributes.eventsGame length	 getGameLength(),getFormattedGameLength()	 MPQ user data headerGame speed	 getGameSpeedText()	 replay.attributes.eventsTeam size	 getTeamSize()	 replay.attributes.eventsMap name	 getMapName()	 replay.detailsWinner(unrealiable)	 getPlayers(),array index 'won'	 replay.game.eventsReplay build	 getBuild()	 MPQ user data headerReplay major version	 getVersion()	 MPQ user data headerGame events	 getEvents()	 replay.game.eventsActions per second	 getPlayers(),array index 'apm'	 replay.game.eventsTotal actions	 getPlayers(),array index 'apmtotal'	 replay.game.eventsChat log	 getMessages()	 replay.message.events

And the following is from the MPQ File.

Constructor¶construct($filename, $autoparse = true, $debug = false)The constructor requires a single parameter, which is the file name of the mpq file. The constructor will open up a file pointer, which will be stored in the member variable fp. Any function reading from the file should always check that fp is valid before attempting a read.The optional parameter $autoparse, if left to its default value of true, will immediately call the parseHeader() -member function. If false, this will have to be done seperately.The optional parameter $debug will make the class generate debug output. Any debug output will go through the private member function debug($string), so if non-default debug destinations or formatting are desired, that can be edited to suit one's needs.Member variablesAll member variables are declared private, and can only be accessed through getters and setters. The only fields with setter functions are the $debug and $debugNewline member variables.Functionsfunction setDebugNewline($str)This function will add an optional suffix to all debug messages. By default it is <br>\n.function setDebug($bool)This function will turn debug messages on or off. Any value that php interprets as non-false will turn debugging on.function parseHeader()This function will parse the MPQ header file, reading both the user data section as well as the actual archive header. Both the hash and block tables, as well as their offsets will be read into their respective variables. For more information about the MPQ format, see http://wiki.devklog.net/index.php?title=The_MoPaQ_Archive_Format. Returns true if parsing was successful, false if it failed for some reason. The member variable init will contain the specific error code and can be read with the member function getState().function getFileSize($filename)Returns the file size or false, if the file does not exist or the header hasn't been parsedfunction getFile($filename)Returns the file contents of a file inside the archive as a string if file exists, or false if an error occurred. As of major version 9, the following files are present in Starcraft 2 replay archives:(attributes)(listfile)replay.attributes.eventsreplay.detailsreplay.game.eventsreplay.initDatareplay.message.eventsreplay.smartcam.eventsreplay.sync.eventsfunction parseReplay()A convenience function for getting an instance of the SC2Replay class with the file contents parsed. Returns an instance of the SC2Replay class with the contents of this MPQFile parsed.function getBuild()Returns the build number, which is present in the user data portion of the header.function getVersion()Returns the major version number, which is present in the user data portion of the header.function getGameLength()Returns the game length in seconds, which is present in the user data portion of the header.

Is that what I need..?

Link to comment
Share on other sites

I don't know... you tell me. What is it that you need to display? Whatever it is, just don't display it - for each such piece, make a field.

Link to comment
Share on other sites

Well, I need to display the Player Name, the Race, the Player Team, the Game Length, the Team Size, the Map Name, the Patch Version, and also a Download to the Chat Log.Do I just copy and paste each of those "get" commands into phpMyAdmin? I'm not sure what you mean by 'posting a field'.

Link to comment
Share on other sites

Where did I say that you post a field? You make one. You define one. You create one.Database tables are like normal tables. A "field" in a database table is like a column in a normal table. You want to have a table that in the end looks like:

=======================================ID | PlayerName	| Race	| PlayerTeam	| ...======================================= 1  | Mesden 	| Zerg 	| No Team		| ...---------------------------------------------------------------------- 2  | boen_robot	| Terran 	| No Team		| ...----------------------------------------------------------------------.... | ... 		| ...	| ...		| ...=======================================

The fields are the columns of the above table. In phpMyAdmin, you need to make/create/define them.

Link to comment
Share on other sites

I see! So when I go into phpMyAdmin it says "Create new table on database Aaron21_Upload". I presume the Name would just be an identifier, but it also asks me for the number of fields.Then when I hit Go, it gives me a bunch more things to put in.FieldTypeLength/Values1Default2CollationAttributesNullIndexAUTO_INCREMENTCommentsWhere do I obtain all that information.

Link to comment
Share on other sites

You don't obtain it. You define it. It can be anything you want/need. See the MySQL manual's description of data types or W3Schools data type reference for a detailed description of each data type.Essentially, what you need is a field for the ID that is of type INT and has AUTO_INCREMENT checked (because you want to later uniquely identify the row by checking this ID; setting it to AUTO_INCREMENT ensures that at every insert, you get a different number), and more fields of VARCHAR or other types. You may leave the other stuff (index, null, attributes, etc.) in phpMyAdmin empty.

Link to comment
Share on other sites

You don't obtain it. You define it. It can be anything you want/need. See the MySQL manual's description of data types or W3Schools data type reference for a detailed description of each data type.Essentially, what you need is a field for the ID that is of type INT and has AUTO_INCREMENT checked (because you want to later uniquely identify the row by checking this ID; setting it to AUTO_INCREMENT ensures that at every insert, you get a different number), and more fields of VARCHAR or other types. You may leave the other stuff (index, null, attributes, etc.) in phpMyAdmin empty.
Okay, I looked these things up on those two websites and I'm a little confused with what kind of coding I'd be putting into those fields... It doesn't look like PHP or HTML...
Link to comment
Share on other sites

phpMyAdmin exists to let you not code, but just select the stuff from the forms it has. Just fill in "the bunch of things" it asks you to fill. I've already told you with what to fill those.If you had to write code, it would be SQL code that looked something similar to the examples at the CREATE TABLE statement (WARNING: For now, ignore everything you see here, or your head will explode).

Link to comment
Share on other sites

phpMyAdmin exists to let you not code, but just select the stuff from the forms it has. Just fill in "the bunch of things" it asks you to fill. I've already told you with what to fill those.If you had to write code, it would be SQL code that looked something similar to the examples at the CREATE TABLE statement (WARNING: For now, ignore everything you see here, or your head will explode).
Wow... I have a headache just looking at that.
Link to comment
Share on other sites

no, the individual values need to be inserted into the mysql table. i believe you need to include or require the functions into your php document somehow, the MPQ document is the reference to these functions. as described below, you will need to construct a MySQL INSERT statement to insert the values into your table. :)i would create the variables for this as $valuename = functionname(); (following the MPQ reference of course), in the PHP after the file has been uploaded and opened, where it is parsed.you will be able to retrieve these values later, perhaps if you intend on keeping a store of the files on the server - to keep a path to the file in each record as another field - unless you want to delete the files after parsing them and inserting the values into the mysql database.upon retrieval, these values can then be compiled from the database into a new file, and made available for download. :)

Link to comment
Share on other sites

no, the individual values need to be inserted into the mysql table. i believe you need to include or require the functions into your php document somehow, the MPQ document is the reference to these functions. as described below, you will need to construct a MySQL INSERT statement to insert the values into your table. :)i would create the variables for this as $valuename = functionname(); (following the MPQ reference of course), in the PHP after the file has been uploaded and opened, where it is parsed.you will be able to retrieve these values later, perhaps if you intend on keeping a store of the files on the server - to keep a path to the file in each record as another field - unless you want to delete the files after parsing them and inserting the values into the mysql database.upon retrieval, these values can then be compiled from the database into a new file, and made available for download. :)
Hrmm.. This isn't making much sense to me. I've been looking at these fields in phpMyAdmin all weekend and I'm just baffled trying to even guess what to put in them...
Link to comment
Share on other sites

Hrmm.. This isn't making much sense to me. I've been looking at these fields in phpMyAdmin all weekend and I'm just baffled trying to even guess what to put in them...
He rarely makes sense :) (that's at least how I feel about it... sorry Pierre).Basically he is saying the same thing I've been telling you for the past few posts - all-in-one. If you haven't understood a thing about what I said, then maybe I too don't make sense.I've already told you what you need to specify in phpMyAdmin - one field of type INT, AUTO_INCREMENT, and make every other field of type VARCHAR. Ignore all other stuff in phpMyAdmin. There's no way to say it in a simpler fashion, except maybe give you a copy&paste-able SQL query code... but I don't think you'll learn anything from it that way.
Link to comment
Share on other sites

He rarely makes sense :) (that's at least how I feel about it... sorry Pierre).Basically he is saying the same thing I've been telling you for the past few posts - all-in-one. If you haven't understood a thing about what I said, then maybe I too don't make sense.I've already told you what you need to specify in phpMyAdmin - one field of type INT, AUTO_INCREMENT, and make every other field of type VARCHAR. Ignore all other stuff in phpMyAdmin. There's no way to say it in a simpler fashion, except maybe give you a copy&paste-able SQL query code... but I don't think you'll learn anything from it that way.
Right but I'm not really sure where to find the values for the INT, AUTO_INCREMENT, etc. Is it in the coding of my upload page? Or is it currently nowhere until I make the values myself?
Link to comment
Share on other sites

its in phpMyAdmin as part of the admin interface that all users see. Have you made a database? Have you made a table in it? When you make a table you have to define the kind of information that will be saved in it. These are known as fields. They have a type definition, auto_increment property, etc.

Link to comment
Share on other sites

Right but I'm not really sure where to find the values for the INT, AUTO_INCREMENT, etc. Is it in the coding of my upload page? Or is it currently nowhere until I make the values myself?
We're starting to go around in circles - you need to make/create/define the kind of content that the table is going to hold. More precisely, you define the kind of content that each column in a row will contain.You do not fill the content itself. Only the kind of content that will later be filled.Once you create a table (i.e. once you specify the kind of content for each column), you can fill actual data in it with insert statements from your PHP code. The ones I told you there's no work around for, and because of which you'll need to write some SQL code. Each time such a statement is executed, it will add a row into the database table.
Link to comment
Share on other sites

Archived

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


×
×
  • Create New...