-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
62 lines (59 loc) · 2.81 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
//require 'php/cookie.php';
include 'header.php';
include "php/connection.php";
ini_set('memory_limit','256M');
ini_set('display_errors', 1);
error_reporting(E_ALL);
$tbl = 'Movies2R';
$countMovies = "SELECT COUNT(*) movie_count FROM ".$tbl;
$row = mysqli_query($conn, $countMovies);
$movieCount = mysqli_fetch_array($row);
echo '<div>Movie Count: '.$movieCount['movie_count'].'</div>';
echo '<div class="main__content" id="main-all">';
echo '<ul class="movies movie--grid">';
if (!isset($_GET['search'])) {
$query = 'SELECT movie_id, new_id, title, media, creation_date, cover FROM '.$tbl;
if ($movies = mysqli_query($conn, $query)) {
while ($movie = mysqli_fetch_assoc($movies) ){
$filename = 'img/'.preg_replace("/[^a-zA-Z0-9]/","",$movie['title']).'_'.$movie['creation_date'].'.jpeg';
echo '<li class="list__item">';
echo "<a class=\"aLink movie--link\" href=\"index.php?select={$movie['movie_id']}\">";
echo '<div class="movie__item">';
echo '<div class="movie__cover"><img src="data:image/jpeg;base64,' . base64_encode($movie['cover']) . '"></div>';
echo '<div id="movie__title">' . $movie['title'] . '</div>';
echo '<div id="movie__media">' . $movie['media'] . '</div>';
//writeCoverFile($conn, $filename, $movie['cover'], $movie['new_id']);
echo '</div>';
echo '</a>';
echo '</li>';
}
}
} elseif (isset($_GET['search'])) {
$query = "SELECT movie_id, title, media, cover FROM movies_all WHERE title REGEXP '({$_GET['search']})'";
if ($movies = mysqli_query($conn, $query)) {
while ($movie = mysqli_fetch_array($movies)) {
echo '<li class="list__item">';
echo "<a class=\"aLink\" href=\"index.php?select={$movie['movie_id']}\">";
echo '<div class="movie__item">';
echo '<div class="movie__cover"><img src="data:image/jpeg;base64,' . base64_encode($movie['cover']) . '"></div>';
echo '<div id="movie__title">' . $movie['title'] . '</div>';
echo '<div id="movie__media">' . $movie['media'] . '</div>';
echo '</div>';
echo '</a>';
echo '</li>';
}
}
}
function writeCoverFile($conn, $filename, $cover, $movieId) {
fwrite(fopen($filename, "w"), $cover);
$coverPath = "UPDATE movies SET coverpath = '$filename' WHERE movie_id = {$movieId} ";
if (mysqli_query($conn, $coverPath)) {
echo '<div>Record has been updated</div>';
} else {
echo '<div>'.mysqli_error($conn).'</div>';
}
}
echo '</ul></div>';
include 'footer.php';
?>