X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=jappixmini%2Fjappix%2Fphp%2Favatar-upload.php;fp=jappixmini%2Fjappix%2Fphp%2Favatar-upload.php;h=73350e15b0db7ab23dd08a6e1e48910f078f27ff;hb=302b2820d104de9f597804da175eccbb7c9c98b1;hp=0000000000000000000000000000000000000000;hpb=61eb1f0d187f639b623b478381973ef93d14f90d;p=friendica-addons.git diff --git a/jappixmini/jappix/php/avatar-upload.php b/jappixmini/jappix/php/avatar-upload.php new file mode 100644 index 00000000..73350e15 --- /dev/null +++ b/jappixmini/jappix/php/avatar-upload.php @@ -0,0 +1,118 @@ + + bad-request +' + ); + +// Get the POST vars +$id = $_POST['id']; +$tmp_filename = $_FILES['file']['tmp_name']; +$old_filename = $_FILES['file']['name']; + +// Get the file extension +$ext = getFileExt($old_filename); + +// Hash it! +$filename = md5($old_filename.time()).$ext; + +// Define some vars +$path = JAPPIX_BASE.'/store/avatars/'.$filename; + +// Define MIME type +if($ext == 'jpg') + $ext = 'jpeg'; + +$mime = 'image/'.$ext; + +// Unsupported file extension? +if(!preg_match('/^(jpeg|png|gif)$/i', $ext)) + exit( +' + forbidden-type +' + ); + +// File upload error? +if(!is_uploaded_file($tmp_filename) || !move_uploaded_file($tmp_filename, $path)) + exit( +' + move-error +' + ); + +// Resize the image? +if(!function_exists('gd_info') || resizeImage($path, $ext, 96, 96)) { + try { + // Encode the file + $binval = base64_encode(file_get_contents($path)); + + // Remove the file + unlink($path); + + exit( +' + '.$mime.' + '.$binval.' +' + ); + } + + catch(Exception $e) { + // Remove the file + unlink($path); + + exit( +' + server-error +' + ); + } +} + +// Remove the file +unlink($path); + +// Something went wrong! +exit( +' + service-unavailable +' +); + +?>