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
https://forums.phpfreaks.com/topic/152146-get-image-size/
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
https://forums.phpfreaks.com/topic/152146-get-image-size/#findComment-799065
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.