2016-04-02 10:25:27 -04:00
|
|
|
<?php
|
2016-04-04 09:00:56 -04:00
|
|
|
include '../credentials.php';
|
2016-04-02 10:25:27 -04:00
|
|
|
|
|
|
|
//Setting up the webpage
|
|
|
|
echo '<html>';
|
|
|
|
echo '<head>';
|
|
|
|
echo '<title>Browse - Meme Machine</title>';
|
|
|
|
echo '<style>img {width:100%;max-width:300px;;padding:7px;}</style>';
|
|
|
|
echo '</head>';
|
|
|
|
echo '<body>';
|
|
|
|
echo '<div align="center">';
|
|
|
|
echo '<h1>Meme Machine</h1>';
|
|
|
|
|
2016-04-02 11:25:29 -04:00
|
|
|
$dir = "../uploads"; // Directory for file uploads
|
|
|
|
$fileType = array( // Types of files that are thumbnail'd
|
2016-04-02 10:25:27 -04:00
|
|
|
'jpg',
|
|
|
|
'jpeg',
|
|
|
|
'png',
|
|
|
|
'gif'
|
|
|
|
);
|
2016-04-02 11:25:29 -04:00
|
|
|
|
|
|
|
// MySQL server connection info
|
|
|
|
|
2016-04-02 10:25:27 -04:00
|
|
|
$count = 0;
|
|
|
|
|
2016-04-02 11:25:29 -04:00
|
|
|
//Connect to MySQL
|
2016-04-02 10:25:27 -04:00
|
|
|
$conn = mysqli_connect($servername, $username, $password, $dbname);
|
|
|
|
|
|
|
|
if (!$conn) {
|
|
|
|
die ("CONNECTION FAIL " .mysqli_connect_error());
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
2016-04-02 11:25:29 -04:00
|
|
|
|
|
|
|
if(isset($_POST["browse"]) && $var) { // If "Browse" is pressed
|
2016-04-02 10:25:27 -04:00
|
|
|
echo '<h2>Category: ' . $_POST["memeCategory"] . '</h2>';
|
|
|
|
$memeCategory = mysqli_real_escape_string($conn, $_POST["memeCategory"]);
|
|
|
|
$browse = "SELECT * FROM memes WHERE category = \"$memeCategory\"";
|
|
|
|
$result = mysqli_query($conn, $browse);
|
|
|
|
|
|
|
|
if (mysqli_num_rows($result) > 0) {
|
|
|
|
while($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$count++;
|
|
|
|
echo '<img src="' . $dir . '/' . $row["fileName"] . '" alt="' . $row["name"] . '" />';
|
|
|
|
if ($count == 3) {
|
|
|
|
echo '<br />';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "This category is empty. Please choose another or start uploading";
|
|
|
|
?>
|
|
|
|
<p> </p>
|
|
|
|
<a href="./">Back</a>
|
|
|
|
<?php
|
|
|
|
}
|
2016-04-02 11:25:29 -04:00
|
|
|
} else { // If 'Browse All' is pressed
|
2016-04-02 10:25:27 -04:00
|
|
|
echo '<h2>Category: all</h2>';
|
|
|
|
$browse = "SELECT * FROM memes";
|
|
|
|
$result = mysqli_query($conn, $browse);
|
|
|
|
//browse all code goes here
|
|
|
|
if (mysqli_num_rows($result) > 0) {
|
|
|
|
while($row = mysqli_fetch_assoc($result)) {
|
|
|
|
$count++;
|
|
|
|
echo '<img src="' . $dir . '/' . $row["fileName"] . '" alt="' . $row["name"] . '" />';
|
2016-04-02 11:25:29 -04:00
|
|
|
if ($count == 3) { // Change this number based on how many pictures across you want on the page
|
2016-04-02 10:25:27 -04:00
|
|
|
echo '<br />';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "Shit, something broke. Try again! Or if the problem persists contact the system administrator";
|
|
|
|
?>
|
|
|
|
<p> </p>
|
|
|
|
<a href="./">Back</a>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</body>';
|
|
|
|
echo '</html>';
|
|
|
|
?>
|