Jump to content

[SOLVED] Image Display


graham23s

Recommended Posts

Hi Guys,

 

i have made a very basic image shack type script where users can upload photos (within size,height,type limitations) everything works good apart from when i try to display the details the user has just uploaded (because they don't have to register i can't use an id to grab the details from mysq or username for that matter) is there another way i can show the user the image they have just uploaded with out an id

 

code:

 

<?php
     ## submission ######################################################################
     if(isset($_POST['upload'])) {
     ## UPLOAD ABOVE ####################################################################
     
     ## VARIABLES #######################################################################
     $filename_of_original_file = $_FILES['userimage']['name'];
     $type_of_original_file = $_FILES['userimage']['type'];
     $size_of_original_file = $_FILES['userimage']['size'];
     $allowed_image_types = array("image/pjpeg","image/gif","image/bmp");
     $max_image_width = 600;
     $max_image_height = 500;
     $max_image_size = 200000;
     
     ## allowed types ###################################################################
     if (!in_array($_FILES["userimage"]["type"], $allowed_image_types)) {
  
     echo '<br /><font color="red">Error:</font> Sorry, That File Type Isn\'t Allowed Please (<a href="javascript: history.go(-1)">Go Back</a>) And Upload Another One.<br /><br />';
     include("includes/footer.php");
     exit;
    
     }
      
     ## height & width ##################################################################
     $dim = getimagesize($_FILES["userimage"]["tmp_name"]);

     if($dim[0] >= $max_image_width || $dim[1] >= $max_image_height) {
  
     echo "<br /><font color=\"red\">Error:</font> Sorry The Maximum Width Is $max_image_width & Maximum Height Is $max_image_height Please (<a href=\"javascript: history.go(-1)\">Go Back</a>) And Upload Another One.<br /><br />";
     include("includes/footer.php");
     exit;
    
     }
      
     ## size is allowed #################################################################
     if ($_FILES["userimage"]["size"] > $max_image_size) {
       
     echo '<br /><font color="red">Error:</font> Sorry, That File Was To Big To Be Uploaded (3mb Max) Please (<a href="javascript: history.go(-1)">Go Back</a>) And Upload Another One.<br /><br />';
     exit;
   
     } 
     
     ## rename the image ################################################################
     $renamed_image = rand(0000000000, 9999999999).".".strtolower(substr($_FILES['userimage']['name'], -3));
     
     ## the upload path #################################################################
     $uploadpath = "uploads/";
     $uploadpath = $uploadpath.$renamed_image;
     
     if(!move_uploaded_file($_FILES["userimage"]["tmp_name"], $uploadpath)) {
     
     echo '<br /><font color="red">Error:</font> Sorry, The Image Could Not Be Uploaded Please (<a href="javascript: history.go(-1)">Go Back</a>) Try Again Later.<br /><br />';
     exit;     
     
     } else {
     
     ## insert the image into mysql #####################################################
     $q = "INSERT INTO `images` (`image_name`,`date`) VALUES ('<img src=\"uploads/$renamed_image\">',now())";
     $r = mysql_query($q) or die (mysql_error());
     
     }
     
     ## TABLE ###########################################################################
     echo '<br />
           <table width="500" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" />
           <tr>
           <td>Image Name:</td><td>'.$filename_of_original_file.'</td>
           </tr>
           <tr>
           <td>Image Size:</td><td>'.$size_of_original_file.' <b>KB</b></td>
           </tr>
           <tr>
           <td>Image Type:</td><td>'.$type_of_original_file.'</td>
           </tr>
           </table><br />'; 
           
     ## image ###########################################################################
     $q2 = "SELECT * FROM `images` 	where `image_name`='$renamed_image'"; 
     $r2 = mysql_query($q2) or die (mysql_error());  
     $row = mysql_fetch_array($r2) or die (mysql_error());
     $image_display = $row['image_name'];
            
     echo '<br />
           <table width="500" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" />
           <tr>
           <td>You Have Uploaded This Image!</td>
           </tr>
           <td>'.$image_display.'</td>
           </table><br />';
     echo '<br />
           <table width="500" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0" />
           <tr>
           <td>Your Image Links</td>
           </tr>
           <td></td>
           </table><br />';  
     ## UPLOAD ABOVE ####################################################################
     include("includes/footer.php");
     exit;          
     }
?>

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/56953-solved-image-display/
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.