
Originally Posted by
Ernie1
getimagesize — Get the size of an image
function will read the header of the file to find out if it's an image or not
getimagesize
Ernie1,
How do I use getimagesize() on the following code, then echo the width and the height of the image on the screen.
Display Images:
Code:
<link rel="stylesheet" type="text/css" href="Index.css" />
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("TS", $con);
$result = mysql_query("SELECT * FROM Images");
while($row = mysql_fetch_array($result))
{
echo '<img class="Thumbnails" src="' . $row['Path'] . '" />';
echo $row['Caption'];
}
mysql_close($con);
?>
Upload Images:
Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("TS", $con);
$sql="INSERT INTO Images (caption)
VALUES
('$_POST[caption]')";
if (($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/jpeg")
&& ($_FILES["file"]["size"] < 90000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$file = ("upload/" . $_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
mysql_query("INSERT INTO Images (caption, path)
VALUES('$_POST[caption]','$file')");
}
}
}
else
{
echo "Invalid file";
}
?>
Bookmarks