Jump to content

get image size


contra10

Recommended Posts

don't really understand the getimagesize function basically i want to get the length and the width of the image before i put it into the db

 

<?php

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 
  
  // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name']; 
  $fileType = $_FILES['image']['type'];
      
  
  // Read the file 
      $fp   = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);


      // Create the query and insert
      // into our database.
      $query = "INSERT INTO `images` (`type`, `image`, `userid`, `username`, `caption`, `city`) VALUES ('" . $fileType . "', '" . $data . "', '" . $id . "', '" . $name . "', '" . $caption . "', '" . $city . "')";
      $results = mysql_query($query) or die(mysql_error());
?>

 

how do i place that in this code

 

Link to comment
Share on other sites

<?php
$query = "INSERT INTO `images` (`type`, `image`, `userid`, `username`, `caption`, `city`,'size') VALUES ('" . $fileType . "', '" . $data . "', '" . $id . "', '" . $name . "', '" . $caption . "', '" . $city . ",".$_FILES['image']['size']."')";
?>

Link to comment
Share on other sites

i want to put the length and width in th db

 

<?php
$caption = mysql_real_escape_string($_POST['caption']);
$name = mysql_real_escape_string($_POST['usernamecookie']);
$city = mysql_real_escape_string($_POST['city']);
$file = mysql_real_escape_string($_FILES['image']);

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 
  
  // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name']; 
  $fileType = $_FILES['image']['type'];
      
  
  
  // Read the file 
      $fp   = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);
  
  list($width, $height) = getimagesize($file);


      // Create the query and insert
      // into our database.
      $query = "INSERT INTO `images` (`type`, `image`, `length`, `width`,`userid`, `username`, `caption`, `city`) VALUES ('" . $fileType . "', '" . $data . "', '" . $width . "', '" . $height . "', '" . $id . "', '" . $name . "', '" . $caption . "', '" . $city . "')";
      $results = mysql_query($query) or die(mysql_error());
      
  // Print results
      print "Thank you, your file has been uploaded.";

?>

 

trying to use the list()

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.