Jump to content

image retrieving from mysql problem


strazdinjsh

Recommended Posts

<?php
/*index.php*/
$menu = $_GET["menu"];
$subm = $_GET["subm"];
$text = " vinu aizsakas vel ilgi pirms.";
$action = $_GET["action"];
require("sys/functions.php");
dbConnect();
displayheader($menu);

/*Home*/
echo '<div class="accordion-toggle">
<a href="aaaaa"><div style="position: absolute; top: 10px; right: 20px; width: 10px; height: 10px; background-color: aqua"></div></a>
<a href="aaaaa"><div style="position: absolute; top: 10px; right: 40px; width: 10px; height: 10px; background-color:blue"></div></a>
<a href="aaaaa"><div style="position: absolute; top: 10px; right: 60px; width: 10px; height: 10px; background-color:green"></div></a>
<a href="aaaaa"><div style="position: absolute; top: 10px; right: 80px; width: 10px; height: 10px; background-color:purple"></div></a>
<a href="aaaaa"><div style="position: absolute; top: 10px; right: 100px; width: 10px; height: 10px; background-color:teal"></div></a>

H O M E</div>
			<div class="accordion-content">
				<div class="bigcontainer">
						<div class="bigcontainertxt">';
						bigContainerWithImageTxt($text);
				echo '</div>';
showLongContainer("img/brown/brownphoto.png", "PHOTOGRAPHY SERVICE", $text);
showLongContainer("img/brown/browndesign.png", "WEB DESIGN", $text);
showLongContainer("img/brown/brownpc.png", "IT SOLUTIONS", $text);

			echo '</div>';
				echo '</div>';
/*Home*/

/*Photography*/	
echo '<div class="accordion-toggle">P H O T O G R A P H Y</div>';
echo '<div class="accordion-content">';
showMenu($subm);

if(isset($subm) and $subm!="")
{
		$Browser = new Browser;
		if ($Browser->Name=="msie")
			$top = -42;
				else
				$top=-30;
	if(get_rows("gallery")>0)
	{
	echo '<div style="position: relative; top: '.$top.'px; z-index: 1;" align="center">';

	?>
	<img src="sample.php?id=42" />
	<?php echo'</div>';
	}
		else
		echo "Sorry";
}
		else
		{
			echo '<div class="bigcontainer">
						<div class="smallcontainerimage"><img src="img/brown/brownphoto.png" /></div>
							<div class="bigcontainertxt">';
							bigContainerWithImageTxt($text);
   					echo '</div>';
		showLongContainer("", "PHOTOGRAPHY SERVICES", $text);
		showLongContainer("", "FOR MODELS", $text);
		showLongContainer("", "GIFT VOUCHERS", $text);
		echo '</div>';
		}
echo '</div>';

/*Photography*/
/*WWW*/
echo '<div class="accordion-toggle">W E B   D E S I G N</div>
			<div class="accordion-content">
				<div class="bigcontainer">
					<div class="bigcontainertxt">';
						bigContainerWithImageTxt($text);
					echo'</div>
						<div class="smallcontainerimage"><img src="img/brown/browndesign.png" /></div>';

														echo '<div class="webcontainer">
														<div class="webcontainertxt">
														<div class="title">
														<a href="" class="title">www.strods.net</a>
														</div><br>dfv sdg asf zc dfv sdg asf zc dfv sdg asf zc dfv sdg asf 
														</div>
														</div>';

														echo '<div class="webcontainer">
														<div class="webcontainertxt">
														<div class="title">
														<a href="" class="title">www.strods.net</a>
														</div><br>dfvsdgasf
														</div>
														</div>';		



														echo '<div class="webcontainer1">
														<div class="webcontainertxt">
														<div class="title">
														<a href="" class="title">www.evergreenlandscapes.ie</a>
														</div><br>dfvsdgasf
														</div>
														</div>';	

														echo '<div class="webcontainer1">
														<div class="webcontainertxt">
														<div class="title">
														<a href="" class="title">www.nautreni.lv</a>
														</div><br>dfvsdgasf
														</div>
														</div>';	






echo '</div>';
echo '</div>';
/*WWW*/
/*PC*/

	echo '<div class="accordion-toggle">I T    S O L U T I O N S</div>
					<div class="accordion-content">
							<div class="bigcontainer">';
								echo'<div class="smallcontainerimage"><img src="img/brown/brownpc.png" /></div>';
										echo '<div class="bigcontainertxt">';
										bigContainerWithImageTxt($text);
										echo '</div>';
	showLongContainer("", "COMPUTER REPAIR", $text);
	showLongContainer("", "RECOVERY", $text);
	showLongContainer("", "MAINTENANCE", $text);
	echo '</div>';
	echo '</div>';

	/*PC*/
	/*Contact Us*/

echo '<div class="accordion-toggle">C O N T A C T   U S</div>
			<div class="accordion-content">';
                              if(isset($action))
                              {
                              $name = CorrectField($_POST["name"]);
                              $email = CorrectField($_POST["email"]);
                              $phone = CorrectField($_POST["phone"]);
                              $message = CorrectField($_POST["message"]);
                              displayForm();
                              	if(CheckField($name, 2)==1 and CheckField($email, 2)==1 and CheckField($phone, 2)==1 and CheckField($message, 2)==1)
                              	{
                              	if(preg_match('/[^a-z A-Z]/', $name) or CheckField($name, 3)==0)
                              	contactError("Please, enter correct name when filling out the form!", "y");
                              			elseif(!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $email) or CheckField($email, 6)==0)
                              			contactError("Please, enter correct email address when filling out the form!", "y");
                              					elseif(!is_numeric($phone) or CheckField($phone, ==0)
                              					contactError("Please, enter correct phone number when filling out the form!", "y");
                              						elseif(CheckField($message, 10)==0)
                              						contactError("Please, enter fully completed text message before sending enquiry!", "y");
                              					
                              		else
                              		{
                              		if(sentEmail($name, $email)==1)
                              		mysql_query("INSERT INTO contacts set name = '$name', email = '$email', phone = '$phone', message = '$message'");
                              		}
                              	}
                              }
                              else
                              displayForm();                            
echo '</div>';		
/*Contact Us*/
displayFooter();
?>

[color=green]<?php
/*sample.php*/
require("sys/functions.php");
dbConnect();


	$id = $_GET["id"];

	if(!isset($id))
	{
	echo "select an ID";
}
			else
			{
			$res = mysql_query("SELECT * FROM gallery where id=$id"); 
			$row = mysql_fetch_assoc($res);
			$image = $row["image"];
  				header("Content-type: image/jpeg");
    			print $image;
    			exit;
    			}
?>
[/color]
<?php
/*part of functions.php*/
function dbConnect()
{
global $DBHOST, $DBUSER, $DBPASSWD, $DBNAME;
        $conn=mysql_connect($DBHOST, $DBUSER, $DBPASSWD);
        if(!$conn)
        {
        echo "Connection with server failed!";
        exit();
        }
        if(!mysql_select_db($DBNAME, $conn))
        {
        echo "Connection with database failed!";
        mysql_close($conn);
        exit();
        }
};
?>

 

edit: added


blocks

Link to comment
Share on other sites

1. i have added function to remove BOM - does not solve the issue

function removeBOM($str)
{
        if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) 
        {
                $str=substr($str, 3);
        }
        return $str;
}

 

2. magic_quotes_runtime was and is ON

 

3. have tried gif, jpg, jpeg, png - none works

 

 

I would appreciate more comments with suggestions and ideas...Thank you

Link to comment
Share on other sites

  • 1 month later...
2. magic_quotes_runtime was and is ON

 

^^^ This is the root cause of your problem.

 

When you used file_get_contents() to read the data and insert it into your database, magic_quotes_runtime already escaped the data and then you unconditionally used mysql_real_escape_string() to escape the data a second time.

 

When magic_quotes (_gpc or _runtime, depending on where the data comes from) is on, you must first use stripslashes() to remove the escape characters that magic_quotes added before you escape the data yourself. You can also turn magic_quotes_runtime off in your script.

 

You apparently have double-escaped data stored in your database (one level of escape characters are actually in the stored data - when data is escaped only once, the escape characters are not stored in the actual database, when data is escaped twice, one set of \ characters is actually in the data) and since magic_quotes_runtime is ON, when you retrieve the data from your database, it is getting escaped at that point as well. (Yes, php.net created a huge blunder when they tried to get the php language to do something that the person writing the code should have been doing only when he wanted it to be done.)

 

A) You should correctly escape (only once) the image data when you store it in the database. The data that is already double-escaped in your database should be removed and reinserted.

 

B) In your code that retrieves the data, you need to turn off magic_quotes_runtime so that the the data won't get escaped in that code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.