Пример #1
0
<?php

require_once 'header.php';
require_once 'php_class/dbaccess_class.php';
require_once 'show_user_images.php';
if (!isset($_SESSION['username'])) {
    echo "You are not logged in.";
    require_once 'footer.php';
    die;
} else {
    $username = $_SESSION['username'];
    $user_id = $_SESSION['user_id'];
    echo "Welcome " . $username . " ! This is your page!" . "<br />";
    echo "<img src='" . showUserImages($user_id) . "'></img>";
    echo ' <a href="logout.php">Logout</a>' . "<br />";
}
if (isset($_POST['submit'])) {
    $image_description = trim($_POST['image_description']);
    $screenshotFilename = trim($_FILES['screenshot']['name']);
    if (!empty($screenshotFilename)) {
        $screenshot = time() . $_FILES['screenshot']['name'];
        $screenshotType = $_FILES['screenshot']['type'];
        $screenshotSize = $_FILES['screenshot']['size'];
        if ($screenshotType == 'image/jpeg' || $screenshotType == 'image/pjpeg' || $screenshotType == 'image/gif' || $screenshotType == 'image/png' && $screenshotSize > 0) {
            $target = './images/' . $screenshot;
            move_uploaded_file($_FILES['screenshot']['tmp_name'], $target);
            $db = new DbAccess();
            $pdo = $db->getPDO();
            $stmt = $pdo->prepare("INSERT INTO image_data (user_id, image_description, image_filename, image_post_date) VALUES (:user_id, :image_description, :image_filename, NOW())");
            try {
                $stmt->execute(array('user_id' => $user_id, 'image_description' => $image_description, 'image_filename' => $target));
Пример #2
0
    $pdo = $db->getPDO();
    $stmt = $pdo->prepare("SELECT image_id FROM image_data WHERE user_id = :user_id");
    try {
        $stmt->execute(array('user_id' => $user_id));
        $row = $stmt->fetchAll();
        return $row;
    } catch (Exception $e) {
        echo 'Message: ' . $e->getMessage() . '<br />';
    }
}
// end showUserImages
function showImage($image_id)
{
    $db = new DbAccess();
    $pdo = $db->getPDO();
    $stmt = $pdo->prepare("SELECT image_filename FROM image_data WHERE image_id = :image_id");
    try {
        $stmt->execute(array('image_id' => $image_id));
        $row = $stmt->fetch();
        return $row['image_filename'];
    } catch (Exception $e) {
        echo 'Message: ' . $e->getMessage() . '<br />';
    }
}
// end showImage
foreach (showUserImages(4571) as $key) {
    foreach ($key as $imggg) {
        echo showImage($imggg);
        echo '<img src="' . showImage($imggg) . '"/>' . '<br />';
    }
}