-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta.php
85 lines (73 loc) · 2.47 KB
/
meta.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require_once(dirname(__FILE__)."/core/core.php");
$start_script_timer = microtime_float();
if(!function_exists('elapsed'))
{
function elapsed($start_time = null)
{
/***
* Return the duration since the start time in
* milliseconds.
* If no start time is provided, it'll try to use the global
* variable $start_script_timer
*
* @param float $start_time in unix epoch. See http://us1.php.net/microtime
***/
if(!is_numeric($start_time))
{
global $start_script_timer;
if(is_numeric($start_script_timer)) $start_time = $start_script_timer;
else return false;
}
return 1000*(microtime_float() - (float)$start_time);
}
}
function returnAjax($data)
{
/***
* Return the data as a JSON object
*
* @param array $data
*
***/
if(!is_array($data)) $data=array($data);
$data["execution_time"] = elapsed();
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
$json = json_encode($data,JSON_FORCE_OBJECT);
$replace_array = array(""",""");
print str_replace($replace_array,"\\\"",$json);
exit();
}
function getUserFileModTime() {
return filemtime("js/c.min.js");
}
function doUploadImage() {
if(empty($_FILES)) {
return array("status"=>false,"error"=>"No files provided","human_error"=>"Please provide a file to upload");
}
$temp = $_FILES["file"]["tmp_name"];
$savePath = dirname(__FILE__) . "/species_photos/";
$file = $_FILES["file"]["name"];
$extension = array_pop(explode(".",$file));
$newFilePath = md5($file) . "." . $extension;
$fileWritePath = $savePath . $newFilePath;
return array("status"=>move_uploaded_file($temp,$fileWritePath),"original_file"=>$file,"wrote_file"=>$newFilePath,"full_path"=>$fileWritePath);
}
if(isset($_SERVER['QUERY_STRING'])) parse_str($_SERVER['QUERY_STRING'],$_REQUEST);
$do = isset($_REQUEST['do']) ? strtolower($_REQUEST['do']):null;
switch($do)
{
case "get_last_mod":
returnAjax(array("last_mod"=>getUserFileModTime()));
break;
case "upload_image":
returnAjax(doUploadImage());
break;
default:
$default_answer = array("status"=>false, "error"=>"Invalid action", "human_error"=>"No valid action was supplied.");
# doUploadImage()
returnAjax($default_answer);
}
?>