I am trying to generate an image report for a particular items. Every item has a unique item number, which is stored in the variable $pk.
In this, calling up images/$pk.jpg and/or screenshots/$pk.jpg will show the relevant image or screenshot for the current item page. This works fine in the actual page, however not in my popup report.
For one file, I wish to trim it to 800px before outputting, without storing the resultant file.
Additionally, people can upload files, so I am trying to retrieve a list of all files uploaded that end in png, and output each of these to the browser.
Below is my code, however only the html header is output.
What am I doing wrong? Is it a misuse of the imagepng method?
my code:
<?php
if (isset($_GET["pk"])) {
$pk = $_GET["pk"];
}
$con = mysqli_connect("localhost","user","pass", "db");
if (!$con) {
echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error();
exit;
} {
echo "<h1>Image report for auction number: ".$pk. "</h1> \n";
$srcName = 'screenshots/'.$pk.'.png';
$info = getimageinfo($srcName);
$src = imagecreatefrompng($srcName);
$dest = imagecreate($info[0], min($info[1], 800));
imagecopy($dest, $src, 0, 0, 0, 0, $info[0], min($info[1], 800));
imagepng($dest);
imagepng('images/'.$pk.'.png');
$filesQuery = "SELECT FILENAME FROM FILES WHERE FILENAME LIKE %png%";
if ($getFiles = $con->prepare($filesQuery)) {
$getFiles->execute();
$getFiles->bind_result($FILENAME);
$files = array();
while ($getFiles->fetch()) {
$filename = array(
'FILENAME' => $FILENAME,
);
$files[] = $filename;
}
}
$filesList = '';
foreach ($files as $filenames) {
$imagepng($filenames['FILENAME']);
}
;
}