5 Jappix - An open social platform
6 This is the avatar upload PHP script for Jappix
8 -------------------------------------------------
12 Last revision: 27/05/11
17 define('JAPPIX_BASE', '..');
19 // Get the needed files
20 require_once('./functions.php');
21 require_once('./read-main.php');
22 require_once('./read-hosts.php');
24 // Optimize the page rendering
28 // Not allowed for a special node
29 if(isStatic() || isUpload())
32 // Set a special XML header
33 header('Content-Type: text/xml; charset=utf-8');
36 if((!isset($_FILES['file']) || empty($_FILES['file'])) || (!isset($_POST['id']) || empty($_POST['id'])))
38 '<jappix xmlns=\'jappix:avatar:post\' id=\'0\'>
39 <error>bad-request</error>
45 $tmp_filename = $_FILES['file']['tmp_name'];
46 $old_filename = $_FILES['file']['name'];
48 // Get the file extension
49 $ext = getFileExt($old_filename);
52 $filename = md5($old_filename.time()).$ext;
55 $path = JAPPIX_BASE.'/store/avatars/'.$filename;
61 $mime = 'image/'.$ext;
63 // Unsupported file extension?
64 if(!preg_match('/^(jpeg|png|gif)$/i', $ext))
66 '<jappix xmlns=\'jappix:avatar:post\' id=\''.$id.'\'>
67 <error>forbidden-type</error>
72 if(!is_uploaded_file($tmp_filename) || !move_uploaded_file($tmp_filename, $path))
74 '<jappix xmlns=\'jappix:file:post\' id=\''.$id.'\'>
75 <error>move-error</error>
80 if(!function_exists('gd_info') || resizeImage($path, $ext, 96, 96)) {
83 $binval = base64_encode(file_get_contents($path));
89 '<jappix xmlns=\'jappix:file:post\' id=\''.$id.'\'>
90 <type>'.$mime.'</type>
91 <binval>'.$binval.'</binval>
101 '<jappix xmlns=\'jappix:file:post\' id=\''.$id.'\'>
102 <error>server-error</error>
111 // Something went wrong!
113 '<jappix xmlns=\'jappix:file:post\' id=\''.$id.'\'>
114 <error>service-unavailable</error>