Current location: Hot Scripts Forums » Programming Languages » PHP » need help with viewing uploaded image on webpage?


need help with viewing uploaded image on webpage?

Reply
  #1 (permalink)  
Old 03-16-04, 08:39 PM
mikewooten mikewooten is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
need help with viewing uploaded image on webpage?

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.

__________________________________________________ _________________-

<!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="text" name="txtCatID">-->
<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:&nbsp;';
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";
}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading an image into database with customerID pecobrown PHP 2 02-27-04 02:11 PM
how to change text dynamically with image? rabbit51 JavaScript 1 02-23-04 09:35 AM
How to change text dynamically with image? rabbit51 Script Requests 0 02-07-04 01:14 PM
Need help on a image slide show using php! xelanoimis PHP 2 10-16-03 07:51 PM
camera phone image poster apt2 Script Requests 2 08-29-03 08:20 PM


All times are GMT -5. The time now is 12:38 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.