i have code for uploading images to my website on my computer, and it works fine, but when I tried to set up the same site on another computer, and a remote server, the images were not coming up.
Any suggestions? Below is the code for
uploading and viewing:
code for creating the thumbnail:
<?php
function getThumb($Original)
{
if (!$Original['name'])
{
//no image supplied, use default
$TempName = "images/noimage.jpg";
$TempFile = fopen($TempName, "r");
$thumbnail = fread($TempFile, fileSize($TempName));
} else
{
//get image
$Picture = file_get_contents($Original['tmp_name']); //reads temp file on server into PHP string var
//create image
$SourceImage = imagecreatefromstring($Picture); //creates image from string
if (!$SourceImage)
{
//not a valid image
echo "Not a valid image\n";
$TempName = "images/noimage.jpg";
$TempFile = fopen($TempName, "r");
$thumbnail = fread($TempFile, fileSize($TempName));
} else
{
//create thumbnail
$width = imageSX($SourceImage);
$height = imageSY($SourceImage);
$newThumb = imagecreatetruecolor(80, 60); //formats thumb to specific size
//resize image to 80 x 60
$result = imagecopyresampled($newThumb, $SourceImage,
0, 0, 0, 0,
80, 60, $width, $height);
//move image to variable
ob_start(); //creates output buffer that stores content
imageJPEG($newThumb); //usually outputs image to browser, here redirects to output area
$thumbnail = ob_get_contents(); //retrieves the content from the buffer area
//stores string value into a PHP string var
ob_end_clean(); // stops the buffering
}
}
return $thumbnail;
}?>
Code for viewing the thumbnail:
<?php
error_reporting(E_ALL);
header("Content-type: image/jpeg");
$prodid = $_GET['id'];
$con = mysql_connect("localhost", "test", "test") or die('');
mysql_select_db("store", $con);
$query = "SELECT picture from products WHERE prodid = $prodid";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$picture = $row['picture'];
echo $picture;
?>
<?php
error_reporting(E_ALL);
include("mylibrary/login.php");
login();
$query = "SELECT prodid, description FROM products";
$result = mysql_query($query) or die(mysql_error());
echo "<table width=\"50%\" cellpadding=\"1\" border=\"1\">\n";
echo "<tr><td>Product ID</td><td>Description</td><td>Image</td></tr>\n";
while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
$prodid = $row['prodid'];
$description = $row['description'];
echo "<tr><td>$prodid</td><td>$description</td>\n";
echo "<td><img src=\"showimage.php?id=$prodid\" width=\"80\" height=\"60\"></td></tr>\n";
}
echo "</table>\n";
?>