Advertisement

07.24.2008 at 07:53AM PDT, ID: 23592298
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

store / retrieve / display ICON files into MySQL database using PHP

Asked by jhines2000 in MySQL Server, PHP Scripting Language

Tags:

Hello All Experts!

I am building a database of ICONS, literally ICO files and would like to display them in a webpage using PHP, MySQL.

I have been able to upload, insert and retrieve / display all images types: JPG, PNG, GIF, etc... however, for the life of me, I cannot get an icon file to display.

I have attached my form, index.php, which allows uploading of images, all types, into MySQL.  That part seems to work fine for all images as I get data going into the database.

I have attached images.php, a small PHP script to loop through and output all images in a simple html table and retrieve_binary_data.php which handles the query/retrieve of the images from the database.

I have attached an icon.zip (icon.ico.zip, please remove .ZIP from the extracted file.  EE doesnt allow ICO files!?) , which is the sample icon I am working with.

Again, all the normal image types display ok, just icons fail :(

I hope this is enough information, Thanks experts!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
*****************************<index.php>
<?php
 
//---------------------
// Connect to Database
//---------------------
include('db_config.php');
 
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
 
$handle      = fopen($tmpName, 'r');
$img = fread($handle , filesize($tmpName));
fclose($handle );
 
if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
 
$img = base64_encode($img); 
 
$sql = "insert into ids_blob values(null,'$fileType','$img','$fileSize', Null, '$fileName');"; 
 
mysql_query($sql) or die('SQL Insert Failed!!!'.mysql_error()); 
 
echo "Success! You have inserted your picture!";
}
?> 
 
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr> 
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile"> 
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
*****************************<end index.php>
 
*****************************<begin images.php>
<?php 
 
include('db_config.php');
 
$query = "SELECT count(*) as num FROM ids_blob";
 
$total_pages = mysql_fetch_array(mysql_query($query));
$nrows = $total_pages[num];
//echo "numrows-".$nrows;
 
echo "<table border='1'><tr align='center' valign='top'>";
for ($i = 1; $i <= $nrows; $i++ ) {
 
	$sql = "select image_id, image_name from ids_blob where image_id ='$i'"; 
	$result = mysql_query($sql) or die('SQL Query Failed!!!'.mysql_error()); 
	$row = mysql_fetch_array($result);
 
	$id = $row['image_id'];
	$name = $row['image_name'];
         //start new row every 10th picture/icon, using PHP modulus to check for perfect division by 10....
	if ($i == (($i-1) % 10 == 0)){
		echo "<tr align='center' valign='top'><td  width ='60'height= '60'>";
		echo $id."<br><img src=\"retrieve_binary_data.php?id=".$id."\">";
		echo "</td>";
	}else{
		echo "<td  width ='60'height= '60'>";
		echo $id."<br><img src=\"retrieve_binary_data.php?id=".$id."\">";
		echo "</td>";
	}
}
echo "</tr></table>";
 
?>
<img src="icon.ico"> <!--- just to prove that an ICON display using a standard html image tag --->
*****************************<end images.php>
 
*****************************<begin retrieve_binary_data.php>
<?php
 
//---------------------
// Connect to Database
//---------------------
 
include('db_config.php');
 
$id = $_GET['id'];
$sql = "select image, image_type from ids_blob where image_id ='$id'"; 
 
$result = mysql_query($sql) or die('Bad query at 12!'.mysql_error()); 
 
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
 
	$db_img = $row['image'];
	$type = $row['image_type'];
 
	$db_img = base64_decode($db_img); //print_r($db_img );
	echo($db_img);
}
imagedestroy($db_img);
?> 
*****************************<end retrieve_binary_data.php>
Attachments:
 
Attached icon
 
[+][-]07.24.2008 at 08:05AM PDT, ID: 22079968

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:18AM PDT, ID: 22080112

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MySQL Server, PHP Scripting Language
Tags: PHP, MySQL
Sign Up Now!
Solution Provided By: hernst42
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.24.2008 at 08:27AM PDT, ID: 22080218

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:29AM PDT, ID: 22080260

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:34AM PDT, ID: 22080307

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:35AM PDT, ID: 22080326

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:50AM PDT, ID: 22080493

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 10:06AM PDT, ID: 22081281

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628