Displaying a user's uploaded posts
Passing the database connection as a variable is a good technique.
Validate user input as much as possible before considering executing any processes.  If the input is missing or invalid, don't do anything with the submission.

if (empty($_GET["user"])) { // add your validation here if possible
    echo "Missing/Invalid data submitted";
    // halt the script or redirect or whatever
}

Use object-oriented mysqli syntax because it is more brief and IMO cleaner to read.
Do not perform iterated queries.  You can easily condense you iterated queries into one simple query using an INNER JOIN.  Something like this should do (untested):

SELECT *
FROM users u
INNER JOIN posts p USING userid 
WHERE u.user_name = ?
  AND p.hostid = p.userid
  AND p.commentid = 0


USING is a convenient shorthand keyword when the two joining columns are identical; otherwise use ON and declare the columns individually. MySQL ON vs USING? You should also replace * in the SELECT clause with the exact columns you need from either table.  (Never ask for more than you need.) With the above query, you will only need to bind $_GET"user"] once since there is now only one placeholder.
I don't typically endorse printing from the same function that does the processing.  If you are going to print nested html elements, you can improve readability by tabbing them.
There is a cleaner way to extract the file extension than picking up post-explosion debris.  How do I get (extract) a file extension in PHP?

$ext = pathinfo($filename, PATHINFO_EXTENSION);

If $row['fileid'] isn't 1 or 2, don't bother printing an empty string.