with the help of daniweb i can now successfully upload photos.& again i showed up with another problem
this time i want to declare different sizes for my phots(passport,stamp etc).so that when ever a customer selects photo type using radio button he can see his selected image in that format.

                <h2><strong>My Album</strong></h2>
                    <fieldset><form action="" method="">





<table align="right" color="red" ><tr><td><label>Order Quantity:-<input type="text" name="number"  style="width: 50px"></td><td>
<input type="radio" name="group1" value="passport" ><b> Passport</b></td>
<td><input type="radio" name="group1" value="stamp" checked><b>Stamp</b></td>
<td><input type="radio" name="group1" value="postcard"><b> Postcard</b></td>

<td><input type="radio" name="group1" value="poster"><b> Poster</b></td>
<td><input type="radio" name="group1" value="greetings"><b> Greetings</b></td>
<td><input type="radio" name="group1" value="collage" checked><b> Collage</b></td>
</tr><br>

<td><input type="submit" name="order" value="Place Order" align="bottom"></td>
</table>

</form>




<?php


$dir = "uploaded/";
if ($opendir = opendir($dir))
{
    while (($file = readdir($opendir)) !== FALSE)
    {
        if ($file!="."&&$file!="..")
        echo "<img src='$dir/$file' height='100' width='100'><br>";


    }



}


?></fieldset>
</body>
</html>

Recommended Answers

All 7 Replies

With HTML you can specify the width and height required, but then the downloaded image is still in original size when downloaded.

With PHP you can use imagecopyresized

i went through my code again and made some adjustment,but my radio button code for different phototypes are not displaying in the selected format(passport,stamp etc).

made some adjustment

What's your new code?

<html>
<head>
<title>Uploading image to MySQL database and displaying it</title>
<script src="disp.js" type="text/javascript" language="javascript"></script>
<script src="ajax.js" type="text/javascript" language="javascript"></script>

<link href="style.css" rel="stylesheet" type="text/css">
</head>
<style type="text/css">
body{
    background-color:#eeeeee;
    font-family:Arial, Helvetica, sans-serif;
}
fieldset{
    width:350px;    
}
fieldset,table,td{  
    font-size:12px;
}
input{
    border:1px solid #999;
}
.error{
    color:red;
    font-size:13px;
    padding:0px 2px;
    background-color: #FFFFCC;
}
.label{
    font-weight:bold;
}
.tablecss{
    background-color:#CCC;
}
.whiterow{
    background-color:#FFF;
}
#imageframe{
    padding:2px; 
    overflow:hidden;
    width:auto;
    height:auto;
    margin-top:5px;
}</style>
<body>
<fieldset>
<legend>Upload Form</legend>
<form enctype='multipart/form-data' name='frmupload' action='' method='POST'>
<input type="hidden" name="MAX_FILE_SIZE" value="524288" />
<input name='filename' type='file'>
<input type='submit' value='Submit' name='submit'>
</form>
</fieldset>
<fieldset><form action="" method="">





<table align="right" color="red" ><tr><td><label>Order Quantity:-<input type="text" name="number"  style="width: 50px"></td><td>
<input type="radio" name="group1" value="passport" ><b> Passport</b></td>
<td><input type="radio" name="group1" value="stamp" checked><b>Stamp</b></td>
<td><input type="radio" name="group1" value="postcard"><b> Postcard</b></td>

<td><input type="radio" name="group1" value="poster"><b> Poster</b></td>
<td><input type="radio" name="group1" value="greetings"><b> Greetings</b></td>
<td><input type="radio" name="group1" value="collage" checked><b> Collage</b></td>
</tr><br>

<td><input type="submit" name="order" value="Place Order" align="bottom"></td>
</table>

</form>
<?php
include("dbconnect.php");

if(isset($_POST['submit'])){

if(is_uploaded_file($_FILES['filename']['tmp_name'])){

    $maxsize=$_POST['MAX_FILE_SIZE'];       
    $size=$_FILES['filename']['size'];

    // getting the image info..
    $imgdetails = getimagesize($_FILES['filename']['tmp_name']);
    $mime_type = $imgdetails['mime']; 

    // checking for valid image type
    if(($mime_type=='image/jpeg')||($mime_type=='image/gif')){
      // checking for size again
      if($size<$maxsize){
        $filename=$_FILES['filename']['name'];  
        $imgData =addslashes (file_get_contents($_FILES['filename']['tmp_name']));
        $sql="INSERT into image(name,image,type,size) values ('$filename','$imgData','".$mime_type."','".addslashes($imgdetails[3])."')";                   
        mysql_query($sql,$link) or die(mysql_error());
      }else{
        echo "<font class='error'>Image to be uploaded is too large..Error uploading the image!!</font>";
      }
    }else{
      echo "<font class='error'>Not a valid image file! Please upload jpeg or gif image.</font>";
    }

}else{          
  switch($_FILES['filename']['error']){
    case 0: //no error; possible file attack!
      echo "<font class='error'>There was a problem with your upload.</font>";
      break;
    case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
      echo "<font class='error'>The file you are trying to upload is too big.</font>";
      break;
    case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
      echo "<font class='error'>The file you are trying to upload is too big.</font>";
      break;
    case 3: //uploaded file was only partially uploaded
      echo "<font class='error'>The file you are trying upload was only partially uploaded.</font>";
      break;
    case 4: //no file was uploaded
      echo "<font class='error'>You must select an image for upload.</font>";
      break;
    default: //a default error, just in case! 
      echo "<font class='error'>There was a problem with your upload.</font>";
      break;
  }     
}   

}

//List Images Part
$sql='SELECT * from image';
$query=mysql_query($sql) or die(mysql_error);
$listimage = "<fieldset>
        <legend>List Images</legend>  
     ";
$listimage.= "
<table cellpadding='1' cellspacing='1' width='300' class='tablecss'>
  <tr class='tablecss'>
    <td nowrap class='label'>Image Name</td>
    <td class='label'>Type</td>
    <td class='label'>Size</td>
  </tr>";
$imageexist=false;
while($result=mysql_fetch_array($query)){
  $imageexist=true;                 
  $listimage.= "
  <tr class='whiterow'>
    <td><a href='javascript:void(0)' onclick='ajaxrequest(\"".$result['id']."\")'>".$result['name']."</a></td>
    <td>".str_replace('image/','',$result['type'])."</td>
    <td nowrap>".$result['size']."</td>
  </tr>";                                        
}

$listimage.= "
</table>
</fieldset>";

if($imageexist){
    echo $listimage;
}

echo "<div id='imageframe'></div>";                   
?>
</body>
</html>

here we go,now images can be uploaded,listed and displayed with my ajax and moto tools....but i dunno how to code those radio buttons inorder to display in the selected radio button type...@prit

You'll need something like the switch for the filename error:

switch ($_POST['group1'])
{
    case 'passport':
        // here output the image in the requested size
        break;
}

okay,but the switch needs to br applied after the photo upload(i may be wrong),and suppose an user selects passport or anyother option,what should be the code inorder to view the image in that very selected format???

what should be the code inorder to view the image in that very selected format?

Back to my first reply. You'll have to choose one of those options.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.