Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

getting image on server to appear

Posted on 2009-12-25
13
Medium Priority
?
236 Views
Last Modified: 2013-12-12
I am trying to get a image that is on the server to show up when a user ID is being looked at.

for instance when a user clicks on a certain button they info for the vendor show from the database. I have images store on the server
vendors/1(which is the id number of that vendor)/image.png

i have the following code but its not showing..did i write this right

$sqlCommand = "SELECT id FROM pages WHERE showing='1' ORDER BY id ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$user_pic = "";
while ($row = mysqli_fetch_array($query)) {
		$check_pic = "vendors/$id/logo.png";
			if (file_exists($check_pic)) {
    		$user_pic = "<img src=\"$check_pic\" width=\"200px\" />"; // forces picture to be 100px wide and no more
	} }

//down in the html sections

<td width="108" rowspan="3"><?php print "$user_pic"; ?></td>

Open in new window

0
Comment
Question by:chefkeifer
  • 7
  • 4
  • 2
13 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26122898
Please post the HTML that was generated by the PHP code above (line 12)
0
 

Author Comment

by:chefkeifer
ID: 26122902
here you go thanks for doing this on Christmas...Merry Christmas by the way
<?php
session_start();


require_once "../Scripts/connect_to_mysql.php";
// Determine which page ID to use in our query below ---------------------------------------------------------------------------------------
if (!$_GET['pid']) {
	$pageid = '1';
} else {
	$pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $body = $row["pagebody"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Store Name
$sqlCommand = "SELECT storename FROM pages WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $title = $row["storename"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//Store Description
$sqlCommand = "SELECT storedescription FROM pages WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $description = $row["storedescription"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Query the module data for display ---------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='footer' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $footer = $row["modulebody"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Query the module data for display ---------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='custom1' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $custom1 = $row["modulebody"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Build Main Navigation menu and gather page data here -----------------------------------------------------------------------------
$sqlCommand = "SELECT id, linklabel FROM pages WHERE showing='1' ORDER BY id ASC"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 

$menuDisplay = '';
while ($row = mysqli_fetch_array($query)) { 
    $pid = $row["id"];
    $linklabel = $row["linklabel"];
	
	$menuDisplay .= '<a href="vendorProfiles.php?pid=' . $pid . '">' . $linklabel . '</a><br />';
	
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT id FROM pages WHERE showing='1' ORDER BY id ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$user_pic = "";
while ($row = mysqli_fetch_array($query)) {
		$check_pic = "vendors/$id/logo.png";
			if (file_exists($check_pic)) {
    		$user_pic = "<img src=\"$check_pic\" width=\"200px\" />"; // forces picture to be 100px wide and no more
	} }
//mysqli_close($myConnection); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Depot at Gibson Mill</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-image: url(../images/brick.png);
	background-repeat: repeat;
}
object {
   outline:none;
}

-->
</style>
<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
</head>

<body>
<table width="888" align="center" cellpadding="6">
  <tr>
    <td align="center"><table width="100%" cellpadding="8">
      <tr>
        <td colspan="2"><table width="100%">
          <tr>
            <td colspan="2" valign="middle"><object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="900" height="215">
              <param name="movie" value="../header_TDG.swf" />
              <param name="quality" value="high" />
              <param name="wmode" value="transparent" />
              <param name="swfversion" value="6.0.65.0" />
              <param name="expressinstall" value="Scripts/expressInstall.swf" />
              <object type="application/x-shockwave-flash" data="../header_TDG.swf" width="900" height="215">
                <param name="quality" value="high" />
                <param name="wmode" value="transparent" />
                <param name="swfversion" value="6.0.65.0" />
                <param name="expressinstall" value="Scripts/expressInstall.swf" />
                <div>
                <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
                <p><a href="http://www.adobe.com/go/getflashplayer">
                <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
                  </div>
                </object>
              </object>
              </td>
            </tr>
          <tr>
            <td width="50%" valign="middle">$logo</td>
            <td width="50%" valign="middle"><?php echo $custom1; ?></td>
            </tr>
          </table>
          </td>
      </tr>
      <tr>
        <td width="24%" align="left" valign="top" background="../images/bkgrd.png" ><?php echo $menuDisplay; ?></td>
        <td width="76%" background="../images/bkgrd.png" >
        <table width="615" border="0" cellpadding="6">
  			<tr><!--this the the table for the descriptions and stuff-->
    			<td width="108" rowspan="3"><?php print "$user_pic"; ?></td>
    			<td width="407"><?php echo $title; ?></td>
    			<td width="56">&nbsp;</td>
  			</tr>
  	  <tr>
    	<td rowspan="2"><?php echo $description; ?></td>
    	<td>&nbsp;</td>
  		</tr>
  	  <tr>
    	<td>More</td>
  	  </tr>
</table>

        </td>
      </tr>
    </table>
    <?php echo $footer; ?></td>
  </tr>
</table>
<script type="text/javascript">
<!--
swfobject.registerObject("FlashID");
//-->
</script>
</body>
</html>

Open in new window

0
 
LVL 11

Expert Comment

by:VanHackman
ID: 26122916
Try my code and let me know what do you get.
<?php

$sqlCommand = "SELECT id FROM pages WHERE showing='1' ORDER BY id ASC";
$user_pic 	= "";
$query 		= mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());


while ($row = mysqli_fetch_array($query))
{
    $check_pic = "vendors/".$row["id"]."/logo.png";
    
	if (file_exists($check_pic))
	{
        $user_pic = '<img src="'.$check_pic.'" width="200px" />'; // forces picture to be 100px wide and no more
		
    }else
	{
		die("Image not found... Please Check the path:".$check_pic);
	}

	echo ('<td width="108" rowspan="3">'.$user_pic.'</td>');
}

?>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:chefkeifer
ID: 26122940
i am getting image not found...i know for sure that the images in the folder on the server
vendors/2/logo.png

0
 

Author Comment

by:chefkeifer
ID: 26122951
ok i put that php code you sent into a test page and changed this code
$check_pic = "vendors/".$row["id"]."/logo.png";

To:
$check_pic = "../vendors/".$row["id"]."/logo.png";

and it worked

but for some reason when i input in with my other script nothing on the whle page shows
<?php
session_start();


require_once "../Scripts/connect_to_mysql.php";
// Determine which page ID to use in our query below ---------------------------------------------------------------------------------------
if (!$_GET['pid']) {
	$pageid = '1';
} else {
	$pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $body = $row["pagebody"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Store Name
$sqlCommand = "SELECT storename FROM pages WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $title = $row["storename"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//Store Description
$sqlCommand = "SELECT storedescription FROM pages WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $description = $row["storedescription"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Query the module data for display ---------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='footer' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $footer = $row["modulebody"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Query the module data for display ---------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='custom1' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while ($row = mysqli_fetch_array($query)) { 
    $custom1 = $row["modulebody"];
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Build Main Navigation menu and gather page data here -----------------------------------------------------------------------------
$sqlCommand = "SELECT id, linklabel FROM pages WHERE showing='1' ORDER BY id ASC"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 

$menuDisplay = '';
while ($row = mysqli_fetch_array($query)) { 
    $pid = $row["id"];
    $linklabel = $row["linklabel"];
	
	$menuDisplay .= '<a href="vendorProfiles.php?pid=' . $pid . '">' . $linklabel . '</a><br />';
	
} 
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT id FROM pages WHERE showing='1' ORDER BY id ASC";
$user_pic       = "";
$query          = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query))
{
    $check_pic = "../vendors/".$row["id"]."/logo.png";
        if (file_exists($check_pic))
        {
        $user_pic = '<img src="'.$check_pic.'" width="200px" />'; // forces picture to be 100px wide and no more
    }else
        {
                die("Image not found... Please Check the path:".$check_pic);
        }}
 }//mysqli_close($myConnection); 
?>

Open in new window

0
 

Author Comment

by:chefkeifer
ID: 26122961
ok fixed it..it works..but its not changing the pic for whatever id is being called..

i have different pic in folders
vendors/1/logo.png
vendors/2/logo.png
vendors/3/logo.png

the number obviously being the id...
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26124397
Is that number somehow related to the $pageid variable that came in the GET string?
0
 

Author Comment

by:chefkeifer
ID: 26124413
i got it to work late last night

i guess what real delima is going to be is that i was just using the logo.png as an example and changing the picture on those respective folders for testing purposes...

if i user uploads a picture to vendors/1/ and its not named logo.png. how do i get the image to display whatever the name or extension may be

0
 
LVL 11

Expert Comment

by:VanHackman
ID: 26124543

I glad to hear that my code works for you.
Don't forget assign some points... ;)

If you use user uploads, you can rename the picture to logo.png and solve the problem easily.

Another options:

1- Save the image name in the DB.
2- Assuming that the"logo" will be the only image in "vendors/id/" you can use scandir() to get the image without worry about the name or extension, I mean something like:


<?php

$dir    = "../vendors/".$row["id"];
$files  = scandir($dir);

foreach($files as $file){

if( (pathinfo($file, PATHINFO_EXTENSION)=='png') ||
    (pathinfo($file, PATHINFO_EXTENSION)=='jpg') ||
    (pathinfo($file, PATHINFO_EXTENSION)=='gif') )
  {

     $pic = $file;
     break;
  }

}

// Finally the logo image is... :
  
   $check_pic = $dir.'/'.$pic;

?>

Open in new window

0
 

Author Comment

by:chefkeifer
ID: 26124618
i used the above code. and the only thing that is displaying is

../vendors/4/1chair.png

its showing the text but the actual picture
//*****=====================================================================================*****
$sqlCommand = "SELECT id, storename, storeDescription FROM pages WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
    $vendorList = '<table border="0" align="center" cellpadding="10">
              ';
    while ($row = mysqli_fetch_array($query)){ 
    $id          = $row["id"];
    $storename   = $row["storename"];
    $storeDescription = $row["storeDescription"];
	$dir    = "../vendors/".$row["id"];
	$files  = scandir($dir);
		foreach($files as $file){
			if( (pathinfo($file, PATHINFO_EXTENSION)=='png') ||	(pathinfo($file, PATHINFO_EXTENSION)=='jpg') ||	(pathinfo($file, PATHINFO_EXTENSION)=='gif') )
			  {
    $pic = $file;
     break;
  }
}
	$user_pic = $dir.'/'.$pic;
    $vendorList .= '
    <tr><td>
    <table width="530" border="1" bordercolor="#FFFFAA" cellpadding="3">
            <tr>
                <td width="25%" rowspan="3" align="center" valign="middle">' . $user_pic . '</td>
                <td width="60%">' . $storename . '</td>
                <td width="20%">&nbsp;</td>
            </tr>
            <tr>
                <td rowspan="2" valign="top" style="font-size:12px">' . $storeDescription . '</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td><a href="http://www.keifersdesign.com/profile.php?id=' . $id . '">See More</a></td>
            </tr>
          </table>
    </td></tr>';

} // close while loop
$vendorList .= '
            </table>  ';
mysqli_free_result($query); 
//*****================================================================================================*****

Open in new window

0
 
LVL 11

Accepted Solution

by:
VanHackman earned 2000 total points
ID: 26124643

Yes buddy, that is because I didn't put the IMG tag in the example...

Here the functional code:
<?php
//*****=====================================================================================*****
$sqlCommand = "SELECT id, storename, storeDescription FROM pages WHERE id='$pageid' LIMIT 1"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
    $vendorList = '<table border="0" align="center" cellpadding="10">
              ';
    while ($row = mysqli_fetch_array($query)){ 
    $id          = $row["id"];
    $storename   = $row["storename"];
    $storeDescription = $row["storeDescription"];
	
        $dir    = "../vendors/".$row["id"];
	
	$files  = scandir($dir);
		
		foreach($files as $file){
			if( (pathinfo($file, PATHINFO_EXTENSION)=='png') ||	(pathinfo($file, PATHINFO_EXTENSION)=='jpg') ||	(pathinfo($file, PATHINFO_EXTENSION)=='gif') )
			  {
				$pic = $file;
				break;
			}
		}
		
	$ThePicture = $dir.'/'.$pic;
    
	$user_pic = '<img src="'.$ThePicture.'" width="200px" />';

	$vendorList .= '
    <tr><td>
    <table width="530" border="1" bordercolor="#FFFFAA" cellpadding="3">
            <tr>
                <td width="25%" rowspan="3" align="center" valign="middle">' . $user_pic . '</td>
                <td width="60%">' . $storename . '</td>
                <td width="20%">&nbsp;</td>
            </tr>
            <tr>
                <td rowspan="2" valign="top" style="font-size:12px">' . $storeDescription . '</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td><a href="http://www.keifersdesign.com/profile.php?id=' . $id . '">See More</a></td>
            </tr>
          </table>
    </td></tr>';

} // close while loop
$vendorList .= '
            </table>  ';
mysqli_free_result($query); 
//*****================================================================================================*****
?>

Open in new window

0
 

Author Comment

by:chefkeifer
ID: 26124655
i should have know that..thanks for you help...i am sure there will be more question from me out there. i am trying to build some sort of cart for many vendors..i am a flash guy and not so much a php, html, mysql guy,..thanks again...

0
 
LVL 11

Expert Comment

by:VanHackman
ID: 26124671

OK buddy, if you have another question just post it and we will help you.
And don't worry about php, html, mysql, etc.
Php is a wonderful Programing language and I am sure that you will learn fast if you keep practicing.

Thanks for the points!.



~VanHackman
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question