Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display an Image on web page 1

Status
Not open for further replies.

nat1967

Technical User
Feb 13, 2001
287
0
0
US
Hi group,

on my web site, a customer can upload a picture to my host server. i would like to display that picture to the customer so they can verify they uploaded the correct one.

currently, my code allows them to choose the picture using a form, then i upload it with PHP. all this works fine but i just cant seem to figure out how to display the image. i have searched php.net and the faq section here but cant seem to quite find what i need. any and all help greatly appreciated.



Have A Great Day!!!, [bigglasses]

Nathan
Software Testing Lead
 
Once you moved the uploaded file into its final location just output an HTML <img> tag with the correct parameters.
Code:
<?
# file moved to img2004.jpg
echo '<img src="'.$filename.'" >';

This seems like an answer that's too easy. What am I missing?
 
hi drj478,

i am fairly new to PHP so i am having a little trouble piecing it together. here is what i have:

foreach($_FILES as $file_name => $file_array) {
$rnd = sprintf("%08d", floor(rand(0,100000000)));

if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'],
"$file_dir/$rnd-$file_array[name]") or die ("Couldnt copy");
chmod("$file_dir/$rnd-$file_array[name]",0644);
//print "<br><br><h2><center><b> File type is valid, and was successfully uploaded.</b></h2><br>\n ";
//print "<h1><b>Congratulations!!!</b></h1><br><br>\n ";
$image = "$rnd-$file_array[name]";

print "Your file has been uploaded to SkyLinePrints.com for processing. Please ";
print "write down your confirmation number listed below and refer to it with ";
print "any questions about your order. <br><br>\n ";

//print "To <strong>complete</strong> your order for a <strong><font color=#FF0000> $msg </font></strong>, choose the <strong>"ADD To Cart" </strong><br>\n ";
//print "button and <strong>complete the checkout process.</strong> <br><br>\n ";
//print "Once payment is confirmed, your order will be processed and shipped immediately. ";
//print "Upon completion, we will send you an email confirming your order is ";
//print "finished and has been shipped. <br><br>\n ";
//print "Thanks for the opportunity to serve you. </center><br><br>\n ";


}

}
}
?>
</div>
<div id="Layer3" style="position: absolute; left: 442px; top: 300px; width: 390px; height: 19px; z-index: 3"><strong>ORDER
CONFIRMATION: <?php echo $rnd; ?></strong></div>
<div id="Layer4" style="position: absolute; left: 508px; top: 325px; width: 239px; height: 66px; z-index: 4">
<form action=" method="post" name="payment" target="paypal" id="payment">
<p>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="wa_dw_3.0.4">
<input type="hidden" name="business" value="skylineprints@bellsouth.net">
<input type="hidden" name="item_name" value="<?php echo $msg; ?>">
<input type="hidden" name="amount" value="<?php echo $pamt; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value=" <input type="hidden" name="cancel_return" value=" <input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="0">

<strong>Step 4:</strong>
<input type="hidden" name="on0" value="CONFIRMATION: <?php echo $rnd; ?>">
<input type="image" name="submit" src=" border="0" alt="It's going to look Great! ">

</p>
</form>
<p></p>
© SkyLinePrints.com</div>
<div id="Layer5" style="position: absolute; left: 566px; top: 395px; width: 123px; height: 19px; z-index: 5">
<p align="center"><a href="../../merchandise/apparel.htm">Back to Shopping</a></p></div>
<div id="Layer6" style="position:absolute; left:394px; top:139px; width:152px; height:151px; z-index:6"><img name="customerpicture" src="<? echo $image; ?>" width="150" height="150" alt="It's going to look GREAT!!"></div>
</body>
</html>

the image wont display. :-( can you offer any suggestions?

Have A Great Day!!!, [bigglasses]

Nathan
Software Testing Lead
 
still very new to php but general observation is that <img src etc. etc. seems to be outside the foreach loop or am I reading it wrong?
 
1. add an echo $image after $image = "$rnd-$file_array[name]"; in order to know wheter the name is correct or not...

2. you have the path "$file_dir/$rnd-$file_array[name]" but "$image" is not using the variable "$file_dir/"... are you getting the correct path?

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top