Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

RomStation.org - Your favorite emulation resource

___

Sponsor

*laugh* No not working on it working with it - as in to put together a code snippet :)  In any case, I'll throw something your way this week.
 

___

Sponsor

Hey I haven't forgot about you by the way, just had a really busy week.  4 sites in various stages of completion to work on at once and deadlines to meet.  I'm still planning on getting this together for you asap if you still need it, I think it'll be a fun little exercise and I might be able to reuse it sometime.
 

___

Sponsor

Doh, actually this time I did forget about it ><  I wrote up some of it, I need to know whether you have pearDB library on your server or not so I can tack in the database connectivity.  If not no worries, I just can't reuse a particular handy piece of code.  I'll check back for your reply ASAP so we can throw it together.

Oh, also, I need to know your file structure so I can set up the dbase structure properly, i.e.:
/system/locale/rom.zip
or
/system/year/rom.zip

Or whatever, and also if you have any particular expectations about the database structure.  Right now I have it set up to use:
  • id - a standard 36 char UUID
  • name - the name of the rom minus the file extension (must be unique)
  • path - path to the file
  • extension - file name extension
  • system - what system it runs on

Anything else you need in there or any specific needs, let me know.

It all fits in one little php script you can run from command line or chron or whatever (though for testing I have it set to automatically start in the current directory, remind me if I forget that and it goes crazy and scans your whole system).  It's configurable so you can tag in file types at your leisure easily from an array toward the top of the file, you'll see it in there when I post it.

Any other ideas / requests?
 

Mortar

Sponsor

Nphyx":1qinet24 said:
Doh, actually this time I did forget about it ><  I wrote up some of it, I need to know whether you have pearDB library on your server or not so I can tack in the database connectivity.  If not no worries, I just can't reuse a particular handy piece of code.  I'll check back for your reply ASAP so we can throw it together.

Oh, also, I need to know your file structure so I can set up the dbase structure properly, i.e.:
/system/locale/rom.zip
or
/system/year/rom.zip

Or whatever, and also if you have any particular expectations about the database structure.  Right now I have it set up to use:
  • id - a standard 36 char UUID
  • name - the name of the rom minus the file extension (must be unique)
  • path - path to the file
  • extension - file name extension
  • system - what system it runs on

Anything else you need in there or any specific needs, let me know.

It all fits in one little php script you can run from command line or chron or whatever (though for testing I have it set to automatically start in the current directory, remind me if I forget that and it goes crazy and scans your whole system).  It's configurable so you can tag in file types at your leisure easily from an array toward the top of the file, you'll see it in there when I post it.

Any other ideas / requests?
PearDB? I dunno anything about PearDB but I do see an option in my control panel which allows me to install something called 'PHP PEAR Packages'. That's all.

As for the file structure, it'll just be 'files/roms/[system]/rom.zip.

I do have two questions, how does the script define the system? Does it look at the directory in which the rom is placed?

Also, what exactly do you mean by 'extension - file name extension'?

Thanks a lot for doing this! :D
 

Chief

Member

ok... i like it kinda... but i gives the feel of a torent or warez place... and those sites scare me... but... hey thats just me.... i can get pretty paranoid when it comes to web design...
 

___

Sponsor

Mortar":ru3cehny said:
PearDB? I dunno anything about PearDB but I do see an option in my control panel which allows me to install something called 'PHP PEAR Packages'. That's all.
pearDB is a nice little library that streamlines interaction with a database.  If you install the PEAR packages it should come with them.
As for the file structure, it'll just be 'files/roms/[system]/rom.zip.

I do have two questions, how does the script define the system? Does it look at the directory in which the rom is placed?
It will pick apart the path to the file and get the system from that.  I will use a regular expression for it, with that structure what I'll do is have it find the last word between two slashes for the system, then the last word before a ., then the string after the dot, anchored to the end of the file, so it'll be /([^/]*)/(.*)\.(.*)$ if you want to test that over at http://www.quanetic.com/regex.php.&nbsp; You could throw some of your filenames in there and see if they all match up properly if you want.
Also, what exactly do you mean by 'extension - file name extension'?
The extension, e.g. zip, rar, iso, cso, rom, whatever.  You can add as many file extensions as you like to the script, there's a spot for it.
Thanks a lot for doing this! :D

NP, it's been a fun little project.  I'm going to use it myself with a few modifications to index my own rom & iso game collection, I will probably throw together a nice little cake app to search it with. :D
 

Mortar

Sponsor

OK, I'll install the PEAR packages.

How far are you with the entire script, if you don't mind my asking? Sorry if I sound impatient, but this script is gonna be a lifesaver.
 

___

Sponsor

Assuming pear installs properly almost done, I just have to test it, otherwise I have to write a little extra code to talk to your database.  So if the former I'll probably do it this evening and post it here, if the latter probably a day or two.  I have a site for a client to finish today, so that's the priority.
 

Mortar

Sponsor

There's a lot of PHP extensions/applications I can install, only two of them having something in common with PEAR, 'QA_Peardoc_Coverage (1.1.1)' and 'Numbers_Words (0.15.0)'. Which one do you need?
 

___

Sponsor

Ah neither of those are it.  You'll probably have to ask your hosting service to set it up in that case, I usuallly have to.  Don't worry about it though, I'll just work without it, it's not a big difference :)  You have mySQL dbase right?
 

___

Sponsor

Okay, here's a provisional copy.  You'll find the SQL necessary to generate the database in the top and the configuration options right below that, it seems like you know PHP enough to figure it out from here.  The syntax for use is
Code:
php rom.php [path]
Where [path] is optional and contains a starting directory.  It will otherwise default to the current working directory.  You want to set this to your web root (or really any directory at least one directory higher than the one containing the individual game system folders) if you run it from a chron task.

Code:
<?php
/**
 * rom.php
 * 
 * scans a filesystem for files matching a given extension and enters them into a database
 * @author Justen Robertson
 * @license GNU/GPL
 * @version 0.5 
 * @updated 5.25.2008
 * @note supports up to 1024/256.8 as path/filename.ext according to dbase spec
 *
********* SQL DBASE ****************
CREATE TABLE `roms` (
`uuid` CHAR( 36 ) NOT NULL ,
`name` VARCHAR( 256 ) NOT NULL ,
`path` VARCHAR( 1024 ) NOT NULL ,
`extension` VARCHAR( 8 ) NOT NULL ,
`system` VARCHAR( 64 ) NOT NULL ,
`size` INT UNSIGNED NOT NULL ,
PRIMARY KEY ( `uuid` )
) ENGINE = MYISAM ;
***********************************
 */

class Config {

/* CONFIGURATION */

	const HOSTNAME		= "localhost";  	// Your host here
	const DATABASE		= "romtest";			// Name of your database
	const USERNAME		= "romtest";			// Database username
	const PASSWORD		= "romtest";			// Database password
	const TABLE				= "roms";					// Name of table in database (in provided SQL, "roms");
	var $file_types	= Array(				// File types to scan for, add more here if you like
		'iso',
		'cso',
		'zip',
		'rar',
		'rom'
		);
	var $debug = false; // set to true to get debug results
	
/* END CONFIG */

	function __construct($debug) {
	$this->debug = $debug;
	}

	function host() {
		return Config::HOSTNAME;
		}
	
	function dbase() {
		return Config::DATABASE;
		}
	
	function user() {
		return Config::USERNAME;
	}
	
	function pass() {
		return Config::PASSWORD;
	}
	
	function table() {
		return Config::TABLE;
	}
	
	function fileTypes() {
		return $this->file_types;
	}
	
	function dbConnect() {
		$comm = mysql_connect($this->host(), $this->user(), $this->pass()) or trigger_error(mysql_error(),E_USER_ERROR);
		return $comm;
		}
}

class Rom {
	private $uuid;
	private $name;
	private $path;
	private $extension;
	private $system;
	private $size;
	private $config;
	
	function __construct($thefile, $theconfig) {
	ereg('.([^\\^/]*).([^\\^/]*)\.(.*)$', $thefile['path'], $m) or die ('System could not be determined for '.$thefile['path']);
	var_dump($m);
	$this->uuid = $this->makeUuid();
	$this->name = $thefile['name'];
	$this->path = addslashes($thefile['path']);
	$this->system = $m[1];
	$this->extension = $thefile['extension'];
	$this->size = $thefile['size'];
	$this->config = clone $theconfig;  // Prevent us from accidentally overwriting global config
	}

/**
  * Generates an UUID
  * 
  * @author     Anis uddin Ahmad <admin@ajaxray.com>
  * @param      string  an optional prefix
  * @return     string  the formatted uuid
  */
	
  function makeUuid($prefix = "") 
  {
    $chars = md5(uniqid(rand()));
    $uuid  = substr($chars,0,8).'-';
    $uuid .= substr($chars,8,4).'-';
    $uuid .= substr($chars,12,4).'-';
    $uuid .= substr($chars,16,4).'-';
    $uuid .= substr($chars,20,12);

    return $prefix . $uuid;
  }
	
	function load ($uuid) {
		$dbase = $this->config->dbConnect();
		$query = "SELECT * FROM `".$this->config->table()."` WHERE `id` = `$id` LIMIT 1 1";
		$result = mysql_query($query, $dbase) or die (mysql_error());
		if (mysql_num_rows($result) > 1) die ("Error: duplicate UUID (??WTF??)");
		$row = mysql_fetch_assoc($result);
		$this->uuid = $row['uuid'];
		$this->name = $row['name'];
		$this->path = addslashes($row['path']);
		$this->system = $row['extension'];
		$this->extension = $row['extension'];
		$this->size = $row['size'];
		mysql_free_result($result);
		if($debug) echo 'Load'.$this->name.' from id: '.$this->id.': SUCCESS';
}

	function save() {
		$dbase = $this->config->dbConnect();
		mysql_select_db($this->config->dbase(), $dbase);	
		$status = false;	// whether the rom exists in the database, false = its new

		$query = "SELECT * FROM `".$this->config->table()."` WHERE `name` LIKE '".$this->name."'";
		if($this->config->debug) echo $query."\n";
		$result = mysql_query($query, $dbase) or die (mysql_error());
		if (mysql_num_rows($result)) { // Check whether we already saved this rom, and if so whether it's been updated
			$status = "exists";
			$current = mysql_fetch_assoc($result);
			$new = Array(
				'uuid' => $this->uuid, 
				'name' => $this->name, 
				'path' => stripslashes($this->path), 
				'system' => $this->system, 
				'extension' => $this->extension, 
				'size' => $this->size
				);
					
			foreach ($current as $key => $value) { // check if anything has been changed
				if ($new[$key] != $value) {
					if ($key == 'uuid' || $key == 'name') {} // don't update UUIDs or names, that's bad mkay
					else if ($updates) {
						$status = "updated"; // set update if anything has been updated
						$updates .= ", `".$key."`='".$new[$key]."'";
					} 
					else {
						$status = "updated"; // set update if anything has been updated
						$updates = "`".$key."`='".$new[$key]."'";
					}
				}
			}
		}
		
		switch ($status) {
			case false : 
			$query = sprintf( "INSERT INTO `%s` (`uuid`, `name`, `path`, `system`, `extension`, `size`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')",
									$this->config->table(),
									$this->uuid,
									$this->name,
									$this->path,
									$this->system,
									$this->extension,
									$this->size
									);
			if($this->config->debug) echo $query."\n";
			mysql_query($query, $dbase) or die (mysql_error());
			return "saved";
			
			case "updated" :
			//if ($this->config->debug) echo "\nTrying to set $updates.";
			$query = sprintf( "UPDATE `%s` SET %s WHERE `name` = '".$this->name."'",
									$this->config->table(),
									$updates
									);
			if($this->config->debug) echo $query."\n";
			mysql_query($query, $dbase) or die (mysql_error());
			if ($this->config->debug) echo "Updated ".$this->name;
			return "updated";
			
			case "exists" :
			if ($this->config->debug) echo "Did not update ".$this->name.": no changes\n";
			return "made no changes";
			
			default :
			if ($this->config->debug) die ("MALFORMED \$update in Rom::save() for ".$this->name." : $update");
		}
	}
}

// ------------ lixlpixel recursive PHP functions -------------
// scan_directory_recursively( directory to scan, filter )
// expects path to directory and optional an extension to filter
// of course PHP has to have the permissions to read the directory
// you specify and all files and folders inside this directory
// ------------------------------------------------------------

// to use this function to get all files and directories in an array, write:
// $filestructure = scan_directory_recursively('path/to/directory');

// to use this function to scan a directory and filter the results, write:
// $fileselection = scan_directory_recursively('directory', 'extension');

function scan_directory_recursively($directory, $filter=FALSE)
{
	// if the path has a slash at the end we remove it here
	if(substr($directory,-1) == '/')
	{
		$directory = substr($directory,0,-1);
	}

	// if the path is not valid or is not a directory ...
	if(!file_exists($directory) || !is_dir($directory))
	{
		// ... we return false and exit the function
		return FALSE;

	// ... else if the path is readable
	}elseif(is_readable($directory))
	{
		// we open the directory
		$directory_list = opendir($directory);

		// and scan through the items inside
		while (FALSE !== ($file = readdir($directory_list)))
		{
			// if the filepointer is not the current directory
			// or the parent directory
			if($file != '.' && $file != '..')
			{
				// we build the new path to scan
				$path = $directory.'/'.$file;

				// if the path is readable
				if(is_readable($path))
				{
					// we split the new path by directories
					$subdirectories = explode('/',$path);

					// if the new path is a directory
					if(is_dir($path))
					{
						// add the directory details to the file list
						$directory_tree[] = array(
							'path'    => $path,
							'name'    => end($subdirectories),
							'kind'    => 'directory',

							// we scan the new path by calling this function
							'content' => scan_directory_recursively($path, $filter));

					// if the new path is a file
					} elseif(is_file($path))
					{
						// get the file extension by taking everything after the last dot
						$extension = end(explode('.',end($subdirectories)));

						// if there is no filter set or the filter is set and matches
						if($filter === FALSE || $filter == $extension)
						{
							// add the file details to the file list
							$directory_tree[] = array(
								'path'      => $path,
								'name'      => end($subdirectories),
								'extension' => $extension,
								'size'      => filesize($path),
								'kind'      => 'file');
						}
					}
				}
			}
		}
		// close the directory
		closedir($directory_list); 

		// return file list
		return $directory_tree;

	// if the path is not readable ...
	}else{
		// ... we return false
		return FALSE;	
	}
}
// ------------------------------------------------------------

	
echo " -- Starting Search --\n";
if ($argc > 2) {
	echo "You passed ".$_SERVER['argc']." arguments.  Usage: php rom.php [/path/to/files/]\n";
}
else if ($argc == 2) {
	$cur_dir = $argv[1];
}
else $cur_dir = getcwd();

echo "Starting in ".$cur_dir.".\n";

$myconfig = new Config();

$scan_results = scan_directory_recursively($cur_dir);

function clean_files($files) {
	$results = Array();

	foreach ($files as $key => $item) {
		if ($item['kind'] == 'directory') {
			if ($myconfig->debug) echo "Recursing for ".$item['name']."\n";
			$results = array_merge($results, clean_files($item['content']));
		}
		else {
			if ($myconfig->debug) echo "Adding ".$item['name']."\n";
			$results []= $item;
		}
	}
	return $results;
	}

$all_roms = clean_files($scan_results);

foreach ($all_roms as $key => $item) {
	if (in_array($item['extension'], $myconfig->fileTypes())) {
		if($myconfig->debug) echo "Found ".$item['name'];
		$therom = new Rom($item, $myconfig);
		$result = $therom->save();
		if($myconfig->debug) echo " and ".$result."\n";
	}
}

	
?>

I tested this and it worked well on my own system, let me know if you have any problems.  You can get a (very) verbose output by changing the $default variable to true in the config area, I didn't provide a cvar for it because... well because I'm lazy, and besides hadn't implemented multiple debug levels so one could cut out mundane messages.

Incidentally the Rom object has a good potential for extension, I built in a load method though it didn't get used.  You could create a Rom() and myrom->load($uuid).

Some things this script does not do:
  • Clean invalid entries from the database (deleted files, etc)
  • Get a UUID from the database during Rom::save() if it discovers an existing rom with the same name; it will keep the UUID it generated for itself during the construction - watch out for this if you extend the code at all and make sure you lookup and set the UUID or you will get SQL duplicate entry errors
  • It assumes each file has a unique name, so it can't store a rom with the same name in a different folder as a separate item in the database - it will simply update the database to the most recent one it finds (so if you have /snes/streetfighter2.zip and /genesis/streetfighter2.zip it will only list one copy of streetfighter2 as an snes title because it scans by alphabetical order)

Oh, right, it's GNU/GPL licensed, but I'd appreciate a thanks in some spot on your site to reference to in my portfolio :D
 

Mortar

Sponsor

Thanks!

Nphyx":goouuioj said:
Okay, here's a provisional copy.  You'll find the SQL necessary to generate the database in the top and the configuration options right below that, it seems like you know PHP enough to figure it out from here.  The syntax for use is
Code:
php rom.php [path]
I'm not sure where to put this syntax. Can you help me?

I am getting this error though:
Code:
-- Starting Search -- Starting in /home/romstati/public_html.
Warning: Missing argument 1 for Config::__construct(), called in /home/romstati/public_html/rom.php on line 315 and defined in /home/romstati/public_html/rom.php on line 45

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

Warning: Invalid argument supplied for foreach() in /home/romstati/public_html/rom.php on line 322

And at the bottom a ton of lines like this one:
array(4) { [0]=> string(32) "/gba/Pokemon Dragonstone (U).zip" [1]=> string(3) "gba" [2]=> string(23) "Pokemon Dragonstone (U)" [3]=> string(3) "zip" }
Any ideas?

P.S. It seems to add the files to the database nonetheless, although it grabs files from other directories as well, such as my include and forums directory. That's not right, is it?

Also, the path entered in the DB is the full path. Isn't it possible for the script to only get the path from the files' directory and up? For example, instead of '/home/romstati/public_html/files/roms/nes/3-D Batt...', it should enter 'nes/3-D Batt...'. And the name shows up with the extension at the end, wasn't it supposed to hide it?

Thanks in advance. :lol:

(I shouldn't go to forums before drinking my coffee, I always end up editing instead of replying ~N)
 

___

Sponsor

Thanks!

Nphyx":2p90irnz said:
Okay, here's a provisional copy.  You'll find the SQL necessary to generate the database in the top and the configuration options right below that, it seems like you know PHP enough to figure it out from here.  The syntax for use is
Code:
php rom.php [path]
I'm not sure where to put this syntax. Can you help me?

I am getting this error though:
Code:
-- Starting Search -- Starting in /home/romstati/public_html.
............
The first error is my bad, I did a quick change to the script last night and forgot about that little thing, at around line 45 change
Code:
	function __construct($debug) {
to
Code:
	function __construct($debug = false) {

It needs to have a default value set.
The latter error is not actually an error, it's just a debug line I forgot to hide when debug is off ><  Go to around line 90 and find
Code:
var_dump($m);
and replace that with
Code:
if($this->config->debug) var_dump($m);

The invalid argument errors are a result of the loop that recurses through the directory structure and picks out the files.  I'd have to look at a full debug dump to figure out why it's showing up, but if it's not causing any problems it might be ignorable ;)  Nonetheless, if you want, set it to run in debug mode and put the output into a text file (it'll be too big for the forum) and I'll have a look at it.

P.S. It seems to add the files to the database nonetheless, although it grabs files from other directories as well, such as my include and forums directory. That's not right, is it?

That's a result of it running from the root directory of your website.  If you're running it from command line, toss the script into the directory right above the directory you want to scan and run it from there, or else supply a path argument.  For instance if your rom directories are in /home/romstati/files/ run it as
Code:
php rom.php "/home/romestati/files"


If you don't have access to a command line, and you're using a management backend like cpanel or something, you should be able to run it as a scheduled task in chron using similar syntax.  It'll probably be

Code:
php /home/romstati/files/rom.php "/home/romstati/files/"

If you absolutely have to run it from a browser, you want to put it somewhere secure. You shouldn't put it inside /public_html/ as anyone who visits your website can trigger it if they happen to bump into the file.  It should be in a secure part of your directory structure not available to outside traffic.  However since you can't pass a command line option from browser I'll have to make a small change to it to allow you to set up a default directory to start in, let me know if you need to do that :)

Also, the path entered in the DB is the full path. Isn't it possible for the script to only get the path from the files' directory and up? For example, instead of '/home/romstati/public_html/files/roms/nes/3-D Batt...', it should enter 'nes/3-D Batt...'. And the name shows up with the extension at the end, wasn't it supposed to hide it?
Yeah I did it like that intentionally so you could get the path to the file directly from the database for the site.  However if you want to change it, you can change:
Code:
	function __construct($thefile, $theconfig) {
	ereg('.([^\\^/]*).([^\\^/]*)\.(.*)$', $thefile['path'], $m) or die ('System could not be determined for '.$thefile['path']);
	if($this->config->debug) var_dump($m);
	$this->uuid = $this->makeUuid();
	$this->name = $thefile['name'];
	$this->path = addslashes($thefile['path']);
	$this->system = $m[1];
	$this->extension = $thefile['extension'];
	$this->size = $thefile['size'];
	$this->config = clone $theconfig;  // Prevent us from accidentally overwriting global config
	}

to
Code:
	function __construct($thefile, $theconfig) {
	ereg('.([^\\^/]*).([^\\^/]*)\.(.*)$', $thefile['path'], $m) or die ('System could not be determined for '.$thefile['path']);
	if($this->config->debug) var_dump($m);
	$this->uuid = $this->makeUuid();
	$this->name = $m[2];
	$this->path = addslashes($m[0]);
	$this->system = $m[1];
	$this->extension = $thefile['extension'];
	$this->size = $thefile['size'];
	$this->config = clone $theconfig;  // Prevent us from accidentally overwriting global config
}
at around line 88.  Note however if you change how the script determines the game name you will need to empty the database before running the script :D
Thanks in advance. :lol:

No worries, I'll check back later today to see how that worked out for you.  Also don't forget to post when you've put the database entries to use on your site, I definitely want to see it in action. :)

Edit:  Grr my indentation dissapeared!
 

Mortar

Sponsor

Thanks! That solved nearly everything. There are two more things that need to be changed though. I want every file to have a normal ID, going upward from 0 (0, 1, 2, 3, etc), so I can use the file info like this: 'http://www.romstation.org/index.php?page=rom&id=[enter id here]'

Also, I would like the script to put the file size in megabytes instead of bytes, rounded up to 2 numbers after the comma.

Oh and about the credits to you, of course, I would be happy to do that. Just tell me where you would like your name and I'll do it.

Thanks.
 

___

Sponsor

Changing away from a UUID is easy enough, just set the UUID field to INT, unique, and auto_increment in your SQL database and rename it to ID for semantic purposes, then change every instance of "UUID" in the code to "ID" (use find and replace), then at line 91 delete:
Code:
	$this->uuid = $this->makeUuid();

SQL should automatically assign a new ID every time you save a new entry.  If that doesn't work let me know, I may be overlooking something - I haven't had my coffee yet this morning. :D

but I have to warn you UUID is a better practice and more future-proof, also you can use it in the same way if you like you just end up with an uglier query string.  The reason is the UUID algorithm ensures a 100% unique identifier (you have something like a 50% chance of having a duplicate UUID if you assign 1 billion UUIDs every second for 100 years)  so if you for instance merge or split your database in the future with another one you can ensure the transition will be clean, or (and this isn't likely) you run out of numbers.  Anyway, that aside, do what works best for you :)

As for the size, you might want to store it as bytes in the database for sake of ease and accuracy, then if you want to display it in megabytes, just divide by 1048576 before you output it, so like
Code:
<dl><dt>File Size:</dt><dd><?php echo number_format(($rom['size']/1048576), 2) ?>mb</dd></dl>
Would get you:
File Size: 53.27mb
if size in bytes is 55858562.

It's generally always best practice to store the most accurate information you can and then reduce it for display where you need to.  However if you're sure you want to reduce it for database storage you can do the same math on the number inside the code, change around line 96:
Code:
	$this->size = $thefile['size'];
to
Code:
	$this->size = number_format($thefile['size']/1048576, 2);

Oh you can throw credit anywhere that works for you on the site,  it doesn't have to be anywhere particularly visible.  Just something I can link to to add to my portfolio. :D

Jeez, this place is starting to look like the scripting forum. : /
 

Mortar

Sponsor

OK, it's perfect now. :D

Thanks for doing this and I'll try to find a good place to give you credits, I was thinking of putting it in the news on my front page, or create some kind of 'special thanks to' page to thank the people that have helped me out. I haven't really thought about it yet, but if you have an idea of where you would like your name, that would be cool.

Thanks again.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top