need help with viewing uploaded image on webpage?

A

Anonymous

Guest
i am a student creating an admin for an ecommerce website and i am working on a page that adds items into the products pages of the ecomerce website. i am trying to display an image on my webpage that
i have uploaded to my server.
i can't seem to get it to work, can anyone help me with any suggestions on how to do this?
the code below is the code that i am using. so far everything seems to work except for getting the image to display on the webpage?
here's the code below!
i can find the uploaded image on my server using FTP, but the only problem is that, that image that just got uploaded, is not showing up on my webpage. i would like for the uploaded image to display on my webpage, but its not doing that, that's what i would like help on.


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 

<html> 
<head> 
    <title>ADD PRODUCTS</title> 
</head> 

<body> 
<strong><center><h3>Add Products</h3></center></strong><br> 

<form action="<? $_SERVER['PHP_SELF']; ?>" method="post" ENCTYPE="multipart/form-data"> 

Choose a product category  <br> 
 
<input type="hidden" name="<? echo '$txtitemId'; ?>"> 
<select name="txtCatID" id="select"> 
                    <option alue="0" SELECTED>0</option> 
                    <option value="1">1</option> 
                    <option value="2">2</option> 
                    <option value="3">3</option> 
</select> 
<br>     

Choose product items to add to your product pages  <br> 
   <input type="hidden" name="<? echo '$txtCatID'; ?>"> 
<select name="txtprodItems" id="select"> 
                    <option alue="Guitars" SELECTED>Guitars</option> 
                    <option value="Drums">Drums</option> 
                    <option value="Amps">Amps</option> 
                    <option value="Books">Books</option> 
</select> 
<br> 

item name<br> 
<input type="text" name="txtItemName"><br> 

item description<br> 
<input type="text" name="txtItemDesc"><br> 

item price<br> 
<input type="text" name="txtItemPrice"><br> 

  upload image<br> 
<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="800000"> 
<INPUT TYPE="HIDDEN" NAME="action" VALUE="1"> 
   <input type="file" name="txtItemImage"><br> 
<input type="submit" name="submit" value="submit"><input type="Reset"> 



<?php if ($HTTP_POST_VARS['action']) { ?>   

<br><FONT FACE="Arial, Helvetica, sans-serif"><FONT SIZE="+1">File Upload 
    Results</FONT> 
<?php   
       
    $uploadpath = '/home/username/public_html/php_cart/p_imgs/';   
      
    $source = $HTTP_POST_FILES['txtItemImage']['tmp_name'];  
    $source_id = $HTTP_POST_FILES['txtItemImage']['id'];  
    $source_name = $HTTP_POST_FILES['txtItemImage']['name'];  
    $source_size = $HTTP_POST_FILES['txtItemImage']['size'];  
    $source_type = $HTTP_POST_FILES['txtItemImage']['type'];  
    $source_error = $HTTP_POST_FILES['txtItemImage']['error'];   
    $dest = '';   
     echo "$upload_tmp_dir";  
    if ( ($source != 'none') && ($source != '' )) {   

        $imagesize = getimagesize($source);   
         

        switch ( $imagesize[2] ) {   

            case 0:   

                echo '<BR> Image is unknown <BR>';  
                //echo "<BR><A HREF='upload.php'>Back</A><br> "; 
                break;   

            case 1:   
                echo '<BR> Image is a GIF <BR>';   
                echo 'Image uploaded!!';   
                //echo "<BR><A HREF='upload.php'>Back</A><br> "; 
                $dest = $uploadpath.uniqid('img').'.gif';   
                break;   
               
            case 2:   
                echo '<BR> Image is a JPG <BR>';   
                echo 'Image uploaded!!';   
                //echo "<BR><A HREF='upload.php'>Back</A><br> "; 
                $dest = $uploadpath.uniqid('img').'.jpg';   
                break;   
               
            case 3:   
                echo '<BR> Image is a PNG <BR>';   
                echo 'Image uploaded!!';  
                //echo "<BR><A HREF='upload.php'>Back</A><br> "; 
                $dest = $uploadpath.uniqid('img').'.png';   
                break;    
        }   
            


    if ($source_type = 'text/plain')  
  {  
    echo '<br>The name of the uploaded files is: ';  
    echo "$source_name";  
  }  
    
// put the file where we'd like it 
  $upfile = $uploadpath . $source_name;  

// is_uploaded_file and move_uploaded_file added at version 4.0.3 
  if (is_uploaded_file($source))   
  {  
     if (!move_uploaded_file($source, $upfile))  
     {  
        echo 'Problem: Could not move file to destination directory';  
        exit;  
     }  
  }   
  else   
  {  
    echo 'Problem: Possible file upload attack. Filename: '.$source_name;  
    exit;  
  }  

        if ( $dest != '' ) {   

            if ( move_uploaded_file( $source, $dest ) ) {   
                   
                echo 'File successfully stored.<BR>';   
                echo '<img src="/php_cart/p_imgs/$source_name">';   
                  
                echo "Name is:".$dest."<br>\n";   
                echo '<img src="php_cart/p_imgs/$dest">';  
                  
            } else {   

                echo '.<BR>';   

            }   

        }    

    } else {   

        echo 'File not supplied, or file too big.<BR>';   

    }   

?>   
</BODY> 
</HTML> 
<?php } else { ?>   
<?php  
 }  
?>    


<?php  

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

    include("db.php");  
      
    // Get a connection to the database 
    $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);  
      
            $txtitemId = $_POST['txtitemId'];  
            $txtCatID = $_POST['txtCatID'];  
            $txtprodItems = $_POST['txtprodItems'];  
            $txtItemName = $_POST['txtItemName'];  
            $txtItemDesc = $_POST['txtItemDesc'];  
            $txtItemPrice = $_POST['txtItemPrice'];  
             
            $txtItemImage = $_POST['txtItemImage'];  

  $theSQL = "update items set prodItems='$txtprodItems', itemName='$txtItemName', 

itemDesc='$txtItemDesc', itemPrice='$txtItemPrice', itemPrice='$txtItemPrice', 

ItemImage='$txtItemImage'";  
   $theSQL = $theSQL . " where itemID = '2'";    

echo "<br><br>";  
    $result = mysql_query($theSQL);   
echo "<br><br>";  

?>   

<?  

#query database 
$sql = "SELECT * FROM items";  
$results = mysql_query($sql);  

#start HTML table for displaying products 
echo "<table border='1'>";  

#run loop to display HTML table of gallery images 

while($products = mysql_fetch_array($results)){  

        echo "<tr> 
                    <td> 
                        <span>".$products[3]."</span><br /> 
<a href=\"add4_1.php?id=".$products[1]."\"> 
<img src='/home/username/public_html/php_cart/p_imgs/".$products[4]."' 
alt='".$products[3]."' /></a></td></tr></table>";  

}  

?>  

<?  
    echo "<br><br>";  
    echo "Thanks, the items have been added to category<br><br>";  
    echo "   
    The items that you have add to the category are: 
      <br> 
     Product Items: $txtprodItems <br> 
    Cat Id:  $txtCatID <br> 
    Item Description: $txtItemDesc <br> 
    Item Price: $ $txtItemPrice <br> 

    Item Image: $txtItemImage   
    ";   

   }  
else  
{  
echo "<br><br><br>You Have To Enter In All Information Before Results Can Show";   
     }  

 ?>
 
well not sure if this is the reason it does not work but it is a problem in your code

Code:
      echo '<img src="/php_cart/p_imgs/$source_name">';

When using single quotes it does not parse the variables.
Code:
      echo '<img src="/php_cart/p_imgs/'.$source_name.'">';

that is the correct way.
 
Code:
echo '<img src="/php_cart/p_imgs/'.$source_name.'" />';

I'm a sucker for valid XHTML. :D
 
Back
Top