Location: PHPKode > projects > HypatiaDB > hypatiadb/import.php
<?php
include("common_db.php");
include("functions.php");
dbconnect($host, $username, $password); //from common_db.php
$strings = loadStrings($lang, 'IMPORT');
headers();
html();
head($strings['IMPORT_TITLE'], array('xhr/create-xhr.php?target=\'xhr/get-data.php?action=tl-ops\'%2BString.fromCharCode(38)%2B\'db=\'%2Bindb&amp;caller=reloadTables&amp;tid=tables&amp;tfunc=clearElem(\'tables\');'));
menu();
navpane();
?>
	<div id="mainpane">
		<?php echo($strings['IMPORT_INTRO']); ?>
		<form action="run-import.php" method="post" enctype="multipart/form-data" class="standalone">
<?php
function return_bytes($val) {			//this hunk of code was shamelessly copied from the
						//php manual for ini_get()
   $val = trim($val);
   $last = strtolower($val{strlen($val)-1});
   switch($last) {
       // The 'G' modifier is available since PHP 5.1.0
       case 'g':
           $val *= 1024;
       case 'm':
           $val *= 1024;
       case 'k':
           $val *= 1024;
   }

   return $val;
}
function make_bytes_friendly($val) {
	global $strings;
	//this function is basically a reverse of the above function
	//(but we need it because the value from 'post_max_size' is
	//not necessarily in shorthand form.)
	$its = 0;
	while($val > 1024 && $its < 5) {
		$val /= 1024;
		$its++;
	}
	$val = intval($val);		//chop off fractions
	switch($its) {
		case 0:
			return sprintf($strings['IMPORT_BYTES'], $val);
			break;
		case 1:
			return sprintf($strings['IMPORT_KB'], $val);
			break;
		case 2:
			return sprintf($strings['IMPORT_MB'], $val);
			break;
		case 3:
			return sprintf($strings['IMPORT_GB'], $val);
			break;
		case 4:
			return sprintf($strings['IMPORT_TB'], $val);
			break;
		//your database is measured in petabytes? Might be time to look into a more
		//"enterprise" file transfer system than HTTP... :)
	}
}

printf($strings['IMPORT_FILESIZE'],return_bytes(ini_get('post_max_size')), make_bytes_friendly(return_bytes(ini_get('post_max_size'))));
?>
			<label for="file"><?php echo($strings['IMPORT_FFILE']); ?><input type="file" name="file" /></label><br />
			<label for="type"><?php echo($strings['IMPORT_FTYPE']); ?><select name="type" onchange="document.getElementById('csvops').style.display='none';document.getElementById('accessops').style.display='none';switch(this.value) { case 'csv': document.getElementById('csvops').style.display='block'; break; case 'mdb': document.getElementById('accessops').style.display='block'; }">
				<option value="mdb" selected="selected"><?php echo($strings['IMPORT_FTMDB']); ?></option>
				<option value="mysql"><?php echo($strings['IMPORT_FTMYSQL']); ?></option>
				<option value="csv"><?php echo($strings['IMPORT_FTCSV']); ?></option>
				<option value="auto"><?php echo($strings['IMPORT_FTAUTO']); ?></option>
				</select></label><br />
<!-- special options for Microsoft Access -->
<div id="accessops">
				<h2><?php echo($strings['IMPORT_MSAHEADING']); ?></h2>
				<p><?php echo($strings['IMPORT_MSAINSTRUCTIONS']); ?></p>
				<label for="msadb"><?php echo($strings['IMPORT_MSADATABASE']); ?><input type="text" name="msadb" /></label>
</div>
<!-- special options for CSVs -->
<div id="csvops" style="display: none">
				<h2><?php echo($strings['IMPORT_CSVHEADING']); ?></h2>
				<label for="lineendings"><?php echo($strings['IMPORT_LEINSTRUCTIONS']); ?></label><br />
				<label for="linenedings"><input type="radio" name="lineendings" value="win" checked="checked" /><?php echo($strings['IMPORT_LEWINDOWS']); ?></label><br />
				<label for="linenedings"><input type="radio" name="lineendings" value="nix" /><?php echo($strings['IMPORT_LENIX']); ?></label><br />
				<label for="dblist"><?php echo($strings['IMPORT_DBLIST']);
echo('<select name="db" id="db" onchange="indb=this.value;reloadTables();"><option>' . $strings['IMPORT_SELECTDBOP'] . '</option>');
//whack out a list of databases
	echo(listDbs('<option value="%1$s">%1$s</option>'));
echo('</select>'); ?></label><div id="tables"></div>
</div>
			<input type="submit" value="<?php echo($strings['IMPORT_FSUBMIT']); ?>" />
		</form>
	</div>
<?php
endhtml();
?>
Return current item: HypatiaDB