2011-11-01 20:05:35 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Upload - Handles uploading files
|
|
|
|
*
|
|
|
|
* Takes an upload request from jquery.filedrop and stores the incoming
|
|
|
|
* files on the server for later viewing.
|
|
|
|
*
|
|
|
|
* @author Andrew Tomaka
|
|
|
|
* @version 1
|
|
|
|
**/
|
|
|
|
|
2011-11-04 18:33:36 -04:00
|
|
|
$conf = json_decode(file_get_contents('database.conf'));
|
2011-11-04 11:30:56 -04:00
|
|
|
|
2011-11-01 20:05:35 -04:00
|
|
|
define('UPLOADS','uploads/');
|
2011-11-02 16:33:57 -04:00
|
|
|
$extensions = array('jpg','jpeg','png','gif','bmp');
|
|
|
|
|
|
|
|
if($_SERVER['REQUEST_METHOD'] != 'POST') {
|
|
|
|
error('request method error');
|
|
|
|
}
|
2011-11-01 20:05:35 -04:00
|
|
|
|
2011-11-02 12:53:58 -04:00
|
|
|
if(array_key_exists('image', $_FILES)) {
|
|
|
|
$file = $_FILES['image'];
|
2011-11-01 20:05:35 -04:00
|
|
|
|
2011-11-02 23:44:18 -04:00
|
|
|
$original = $file['name'];
|
|
|
|
$extension = explode('.',$original);
|
2011-11-02 16:33:57 -04:00
|
|
|
$extension = array_pop($extension);
|
|
|
|
$extension = strtolower($extension);
|
|
|
|
|
|
|
|
//if(!in_array(strtolower(array_pop(explode('.',$file['name'])),$extensions))) {
|
|
|
|
if(!in_array($extension,$extensions)) {
|
|
|
|
error('file extension error.');
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:44:18 -04:00
|
|
|
$db = mysqli_init();
|
|
|
|
$db->real_connect($conf->hostname, $conf->username, $conf->password, $conf->database);
|
2011-11-04 11:30:56 -04:00
|
|
|
$query = "INSERT INTO screens (extension, original) VALUES('$extension','$original')";
|
2011-11-02 23:44:18 -04:00
|
|
|
$db->query($query);
|
|
|
|
$newId = $db->insert_id;
|
2011-11-02 16:33:57 -04:00
|
|
|
|
2011-11-04 11:30:56 -04:00
|
|
|
if(move_uploaded_file($file['tmp_name'], UPLOADS . $newId . '.' . $extension)) {
|
2011-11-04 21:41:18 -04:00
|
|
|
echo json_encode(array('type'=>'success','status'=>'Uploaded successfully','file'=>'http://screens.p5dev.com/' . $newId));
|
2011-11-02 16:33:57 -04:00
|
|
|
exit;
|
|
|
|
}
|
2011-11-01 20:05:35 -04:00
|
|
|
}
|
2011-11-02 16:33:57 -04:00
|
|
|
error('unknown error');
|
2011-11-01 20:05:35 -04:00
|
|
|
|
2011-11-02 16:33:57 -04:00
|
|
|
|
|
|
|
function error($message) {
|
|
|
|
echo json_encode(array('type'=>'error','status'=>$message));
|
|
|
|
exit;
|
|
|
|
}
|
2011-11-01 20:05:35 -04:00
|
|
|
?>
|