Skip to content

Commit

Permalink
API Avatars: added id fetching
Browse files Browse the repository at this point in the history
Avatars fetching by id
  • Loading branch information
fet1sov committed Apr 9, 2024
1 parent f130c90 commit 9d465ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/*
* User routes
*/
$router->add("/user", "routes/user/user.ctrl.php");
$router->add("/user/{category}", "routes/user/user.ctrl.php");

/*
* API routes
Expand Down
12 changes: 9 additions & 3 deletions routes/api/api.ctrl.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php

$avatarFilePath = $_SERVER["DOCUMENT_ROOT"] . '/uploads/avatars/no_avatar.png';
$avatarsPath = $_SERVER["DOCUMENT_ROOT"] . '/uploads/avatars/';

if (isset($_REQUEST["userid"]) && file_exists())
{
$avatarFilePath = $avatarsPath . $_REQUEST["userid"] . ".png";
} else {
$avatarFilePath = $avatarsPath . 'no_avatar.png';
}

$fp = fopen($avatarFilePath, 'rb');
// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
// dump the picture and stop the script
fpassthru($fp);
exit;

0 comments on commit 9d465ad

Please sign in to comment.