SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2005
    Posts
    527
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thumbnail problem

    Hi

    I have a code that upload my image :

    Code:
    	if ($_POST['submit']){
    		$name = $_POST['name'];
    		$price = $_POST['price'];
    		$cid = $_POST['cid'];
    		$fileName = $_FILES['userfile']['name'];
    		$tmpName  = $_FILES['userfile']['tmp_name'];
    		$fileSize = $_FILES['userfile']['size'];
    		$fileType = $_FILES['userfile']['type'];
    		if ($name and $fileName){
    			if ($fileSize > 700000)
    				die('please choice a little file');
    			$fp      = fopen($tmpName, 'r');
    			$content = fread($fp, filesize($tmpName));
    			$content = addslashes($content);
    			fclose($fp);
    	
    			if(!get_magic_quotes_gpc())
    			{
        			$fileName = addslashes($fileName);
    			}
    						$query = "INSERT INTO product set name='$name' , price=$price , description='$permission' ,file_name='$fileName', file_size='$fileSize', file_type='$fileType', file_content='$content',cid=$cid";
    			
    			//$query = "INSERT INTO product (name , price , description ,file_name, file_size, file_type, file_content ) VALUES ('$name',$price,'$description','$fileName', '$fileSize', '$fileType', '$content')";
    			mysql_query($query) or die(mysql_error());
    			echo 'ok';
    		}else{
    			echo 'error';
    		}

    And I show the thumbnail from :

    Code:
    require_once('dbconn.php');
    	$id= $_GET['id'];
    	$place = $_GET['place'];
    	if ($place == 'big'){
    		$query = "SELECT file_name, file_type, file_size, file_content FROM product WHERE id = '$id'";
    		 
    	}else if ($place == 'product')
    	{
    		$imgh = 100;
    		$query = "SELECT file_name, file_type, file_size, file_content FROM product WHERE id = '$id'";		
    	}else if ($place == 'category'){
    		$imgh = 150;
    		$query = "SELECT file_name, file_type, file_size, file_content FROM category WHERE id = '$id'";		
    	}
    		$result = mysql_query($query) or die(mysql_error());
    		list($name, $type, $size, $content) =                                  
    		mysql_fetch_array($result);
    		
    		
    		
    		$im = imagecreatefromstring($content);
       		$width  = imagesx($im);
       	 	$height = imagesy($im);
        	if (isset($imgh)){
        		$imgw = $height / $width * $imgh; 
        	}else{
        		$imgw = $width;
        		$imgh = $height;
        	}
    		$thumb=ImageCreate($imgw,$imgh);
       		imagecopyresampled($thumb,$im,0,0,0,0,$imgw,$imgh,ImageSX($im),ImageSY($im));
    
        	
        	header("Content-length: $size");
    		header("Content-type: $type");
    		//header("Content-Disposition: attachment; filename=$name");
    		$out = ImagejpeG($thumb);
        	print($out);
       		imagedestroy ($im);
        	imagedestroy ($thumb); 
    }

    but when I upload some files I have some breaked pictures with bad sizes
    what is the code s problem ?

  2. #2
    SitePoint Evangelist
    Join Date
    Dec 2005
    Posts
    527
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is mya code`s problem ?

    who can show me a code for creating thumbnail from images in database ?

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Posts
    613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've never understood why people get images out of and store them in databases....

  4. #4
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    365
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Webnet View Post
    I've never understood why people get images out of and store them in databases....
    I am starting to hear a bit about storing XML in the dataabse too!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •