Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize image for blob

Status
Not open for further replies.

JamesGMills

Programmer
Aug 15, 2005
157
GB
Hi, Happy Christmas... this is what i have so far:

<?
if(!empty($_FILES)) {

require_once("includes/dbc.inc.php");

$filename = $_FILES['file']['name']; // Get the client side file name
$tempFilename = $_FILES['file']['tmp_name']; // Temporary file name server side
$fileSize = $_FILES['file']['size']; // size of uploaded file
$fileType = $_FILES['file']['type']; // File type

$fileNameParts = explode(".", $filename); // Get file extension
$fileExtension = $fileNameParts[1]; // Part behind last dot
$filenameNoExt = $fileNameParts[0]; // File name with no extension

$tempFileOpen = fopen($tempFilename, "r"); // Read file
$binaryImage = fread($tempFileOpen, fileSize($tempFilename)); // Create binary image for blob in db
$binaryImage = addslashes($binaryImage);

// Create thumbnail
$originalWidth = imagesx($tempFilename); // get original source image width
$originalHeight = imagesy($tempFilename); // and height

$dateAdded = date("Y-m-d G:i:s"); // Time record added

// Add to database
$dbConnect = db_connect("****");
$query = "INSERT INTO Images (ID, Title, Image, Thumbnail, DateAdded, FileType, FileSize, FileName) VALUES ('', '$filenameNoExt','$binaryImage' ,'' , '$dateAdded', '$fileType', '$fileSize', '$filename')";
$result = mysql_query($query, $dbConnect) or die(mysql_error());
}
?>

I would like to resize the image before I save it to the database. I will then use this same idea to create a thumbnail.

The problem that I am finding is that most of the script examples I have found so far all resize images from a folder not directly from a form and so i am slightly stuck right now.

Cheers for any advice, guidance.

James

------------------------
 
Here's the code to get the image out of the blob field:
Code:
<? 
Header("Content-Type: image/jpeg"); 

$dbh=mysql_connect ("localhost", "tlrcuser_4_w", "PpEAhHe8") or die('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("tlrcuser_woodensimolean"); 

$ColumnName = $HTTP_GET_VARS['ColumnName'];
$sql = 'SELECT '.$ColumnName.' FROM `MasterMeshList` WHERE RecNum=' ;
$sql .= $HTTP_GET_VARS['RowNum']."\n";
// echo $sql;
$result = mysql_query($sql,$dbh) or die("Query failed : " . mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);

$im = imagecreatefromstring ($line[$ColumnName]); 
ImageJPEG($im); 
ImageDestroy($im);

/* Free resultset */
mysql_free_result($result);

/* Closing connection */
mysql_close($dbh);

?>

I can't find the code I used to put the data in the database tho.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top