Main content: Introduce the picture upload process, involve PHP and jquery;
1. Read the configuration file and connect to the MySQL database.
Configuration files are mainly real username and password.
3-5.php
<?php
/*
* version : 20141108
*/
/*
* Define a constant
*/
Define("EQUAL","=");
Define("SPACE","");
Function get_content($file){
If(!file_exists($file)) return false;
Return file_get_contents($file);
}
Function get_config($str, $ini, $type="string"){
If ($type=="int"){
$config = preg_match("/".preg_quote($ini)."=(.*);/", $str, $res);
If($config==0) return false;
}
Else{
$config = preg_match("/".preg_quote($ini)."=\"(.*)\";/", $str, $res);
If($config==0) return false;
}
$result=explode(EQUAL,$res[0]);
Return preg_replace("/(\"|\‘|;)/",SPACE,$result[1]);
}
?
>
2. Connect MySQL database;
This uses the ODBC classes provided by PHP.
First install the data source driver, class such as Mysql-connector-odbc-5.3.4-win32. Then the configuration is OK in ODBC data source management.
2.1 Connection operation for the write database
<?php
/*
* version : 20141109
* made dy : neojos
*/
Include_once("3-5.php");
Class dbSource{
Function __construct(){
$dbString=get_content("config.ini");
$server=get_config($dbString,"server");
Echo $dbname=get_config($dbString,"userName");
Echo $dbpwd=get_config($dbString,"password");
Odbc_connect("DRIVER={MySQL ODBC 5.3 ANSI Driver};", $dbname, $dbpwd) or handle_error("", odbc_error());
}
Function handle_error($user_error_message,$system_error_message){
Header("Location:3-6.php?"."error_message={$user_error_message}&".
"system_error={$system_error_message}");
Exit();
}
}
$db=new dbSource();
?
>
jquery Learning (4-2-phpserver end 1)