add: remove original texture automatically before uploading
This commit is contained in:
parent
5553978328
commit
1bfcb343c7
|
|
@ -3,7 +3,7 @@
|
||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-01-16 23:01:33
|
* @Date: 2016-01-16 23:01:33
|
||||||
* @Last Modified by: prpr
|
* @Last Modified by: prpr
|
||||||
* @Last Modified time: 2016-01-17 12:02:23
|
* @Last Modified time: 2016-01-21 22:33:37
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class user {
|
class user {
|
||||||
|
|
@ -63,9 +63,12 @@ class user {
|
||||||
public function setTexture($type, $file) {
|
public function setTexture($type, $file) {
|
||||||
$hash = utils::upload($file);
|
$hash = utils::upload($file);
|
||||||
if ($type == "skin") {
|
if ($type == "skin") {
|
||||||
|
// remove the original texture first
|
||||||
|
utils::remove("./textures/".$this->getTexture('skin'));
|
||||||
return utils::update($this -> uname, 'skin_hash', $hash);
|
return utils::update($this -> uname, 'skin_hash', $hash);
|
||||||
echo "shit";
|
echo "shit";
|
||||||
} else if ($type == "cape") {
|
} else if ($type == "cape") {
|
||||||
|
utils::remove("./textures/".$this->getTexture('cape'));
|
||||||
return utils::update($this -> uname, 'cape_hash', $hash);
|
return utils::update($this -> uname, 'cape_hash', $hash);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-01-16 23:01:33
|
* @Date: 2016-01-16 23:01:33
|
||||||
* @Last Modified by: prpr
|
* @Last Modified by: prpr
|
||||||
* @Last Modified time: 2016-01-21 21:59:47
|
* @Last Modified time: 2016-01-21 22:26:07
|
||||||
*/
|
*/
|
||||||
$dir = dirname(dirname(__FILE__));
|
$dir = dirname(dirname(__FILE__));
|
||||||
require "$dir/config.php";
|
require "$dir/config.php";
|
||||||
|
|
@ -14,7 +14,7 @@ class utils {
|
||||||
/**
|
/**
|
||||||
* Connect to database
|
* Connect to database
|
||||||
*
|
*
|
||||||
* @return null
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function connect() {
|
public static function connect() {
|
||||||
if (!self::$connection) {
|
if (!self::$connection) {
|
||||||
|
|
@ -31,9 +31,9 @@ class utils {
|
||||||
/**
|
/**
|
||||||
* Use static function to replace raising a exception
|
* Use static function to replace raising a exception
|
||||||
*
|
*
|
||||||
* @param {integer} errno
|
* @param int $errno
|
||||||
* @param {string} msg, message to show
|
* @param string $msg, message to show
|
||||||
* @return null
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function raise($errno = -1, $msg = "Error occured.") {
|
public static function raise($errno = -1, $msg = "Error occured.") {
|
||||||
$exception['errno'] = $errno;
|
$exception['errno'] = $errno;
|
||||||
|
|
@ -42,11 +42,11 @@ class utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return array of rows which matches provided key adn value
|
* Return array of rows which matches provided key and value
|
||||||
*
|
*
|
||||||
* @param {string} key
|
* @param string $key
|
||||||
* @param {string} value
|
* @param string $value
|
||||||
* @return {array} row array returned by mysql_fetch_array()
|
* @return array $row, rows matched the key and value
|
||||||
*/
|
*/
|
||||||
public static function select($key, $value) {
|
public static function select($key, $value) {
|
||||||
$query = self::query("SELECT * FROM users WHERE $key='$value'");
|
$query = self::query("SELECT * FROM users WHERE $key='$value'");
|
||||||
|
|
@ -57,8 +57,8 @@ class utils {
|
||||||
/**
|
/**
|
||||||
* Insert a record to database
|
* Insert a record to database
|
||||||
*
|
*
|
||||||
* @param {array} array, [uname, passwd, ip]
|
* @param array $array, [uname, passwd, ip]
|
||||||
* @return boolean
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function insert($array) {
|
public static function insert($array) {
|
||||||
$uname = $array['uname'];
|
$uname = $array['uname'];
|
||||||
|
|
@ -77,8 +77,8 @@ class utils {
|
||||||
/**
|
/**
|
||||||
* Rename uploaded file
|
* Rename uploaded file
|
||||||
*
|
*
|
||||||
* @param {array} file, files uploaded via HTTP POST
|
* @param array $file, files uploaded via HTTP POST
|
||||||
* @return {string} hash, file's sha256 hash
|
* @return string $hash, sha256 hash of file
|
||||||
*/
|
*/
|
||||||
public static function upload($file) {
|
public static function upload($file) {
|
||||||
move_uploaded_file($file["tmp_name"], "./textures/tmp.png");
|
move_uploaded_file($file["tmp_name"], "./textures/tmp.png");
|
||||||
|
|
@ -87,11 +87,25 @@ class utils {
|
||||||
return $hash;
|
return $hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a file
|
||||||
|
*
|
||||||
|
* @param $filename
|
||||||
|
* @return $bool
|
||||||
|
*/
|
||||||
|
public static function remove($filename) {
|
||||||
|
if (!unlink($filename)) {
|
||||||
|
self::raise(-1, "Uncaught error when deleting $filename");
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple SQL injection protection
|
* Simple SQL injection protection
|
||||||
*
|
*
|
||||||
* @param {string} string, string to convert
|
* @param string $string
|
||||||
* @return {string}
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function convertString($string) {
|
public static function convertString($string) {
|
||||||
return stripslashes(trim($string));
|
return stripslashes(trim($string));
|
||||||
|
|
@ -100,8 +114,8 @@ class utils {
|
||||||
/**
|
/**
|
||||||
* Query with raw SQL statement
|
* Query with raw SQL statement
|
||||||
*
|
*
|
||||||
* @param {string} sql, raw SQL statement
|
* @param string $sql, raw SQL statement
|
||||||
* @return {boolean}
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function query($sql) {
|
private static function query($sql) {
|
||||||
self::connect();
|
self::connect();
|
||||||
|
|
@ -114,6 +128,13 @@ class utils {
|
||||||
mysql_close(self::$connection);
|
mysql_close(self::$connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of key in an array if index exist
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param array $array
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
function getValue($key, $array) {
|
function getValue($key, $array) {
|
||||||
if (array_key_exists($key, $array)) {
|
if (array_key_exists($key, $array)) {
|
||||||
return $array[$key];
|
return $array[$key];
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.6 KiB |
Loading…
Reference in New Issue
Block a user