Reaper0167 Posted February 10, 2009 Share Posted February 10, 2009 php mysql search engine displays the blob image like this....what is going on? ‡ÿêB™\€„Àt‘8K€@zŽB¦@F€˜&S `ËcbãP-`'æÓ€ø™{[”! ‘ eˆDh;¬ÏVŠEX0fKÄ9Ø-0IWfH°·ÀÎ ² 0Qˆ…){`È##x„™FòW<ñ+®ç*x™²<¹$9E[-qWW.(ÎI+6aaš@.Ây™24àóÌ ‘àƒóýxήÎÎ6޶_-ê¿ÿ"bbãþåÏ«p@át~Ñþ,/³€;€mþ¢%îh^ u÷‹f²@µ éÚWópø~<ß5°j>{‘-¨]cöK'XtÀâ÷ò»oÁÔ(€hƒáÏwÿï?ýG %€fI’q^D$.Tʳ?ÇD *°AôÁ,ÀÁÜÁ ü`6„B$ÄÂBB d€r`)¬‚B(†Í°*`/Ô@4ÀQh†“p.ÂU¸=púažÁ(¼ AÈa!ÚˆbŠX#Ž™…ø!ÁH‹$ ɈQ"K‘5H1RŠT UHò=r9‡\Fº‘;È2‚ü†¼G1”²Q=Ô µC¹¨7„F¢ Ðdt1š ›Ðr´=Œ6¡çЫhÚ>CÇ0Àè3Äl0.ÆÃB±8, “c˱"¬ «Æ°V¬»‰õcϱwEÀ 6wB aAHXLXNØH¨ $4Ú 7 „QÂ'"“¨K´&ºùÄb21‡XH,#Ö/{ˆCÄ7$‰C2'¹I±¤TÒÒFÒnR#é,©›4H#“ÉÚdk²9”, +È…ääÃä3ää!ò[ b@q¤øSâ(RÊjJåå4åe˜2AU£šRݨ¡T5ZB¡¶R¯Q‡ Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/ Share on other sites More sharing options...
jeger003 Posted February 10, 2009 Share Posted February 10, 2009 you should post your code so we can see whats going on Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-758622 Share on other sites More sharing options...
genericnumber1 Posted February 10, 2009 Share Posted February 10, 2009 You likely need to send the image header... Place header('Content-type:image/jpeg'); at the top or whatever type of image it is (above if it's jpeg, replace jpeg with png if it's a png, etc). Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-758623 Share on other sites More sharing options...
Reaper0167 Posted February 10, 2009 Author Share Posted February 10, 2009 I will post the code here in a little while. The images are bmp, png, jpg and gif. I was told that you cannot display all those types on one page, but I find that hard to believe. I will try the header now. Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-758624 Share on other sites More sharing options...
Reaper0167 Posted February 10, 2009 Author Share Posted February 10, 2009 by the way, this is not my script, i was just wondering how good it worked so I could get an idea of search engines. I tried the header code at the top of the page and all it shows is a little box with an x in the middle. And all the other content on the page was missing. <?php header('Content-type:image/x-png'); include "upload_db_info.php"; // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("----","-----","-------"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("-------") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from $table_name where name like \"%$trimmed%\" order by name"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; // google echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["content"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-758628 Share on other sites More sharing options...
genericnumber1 Posted February 10, 2009 Share Posted February 10, 2009 You have to give the images their own page which you then link to with the html img tag, that's what people meant by "you can't have all of the images on one page" Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-758669 Share on other sites More sharing options...
Reaper0167 Posted February 10, 2009 Author Share Posted February 10, 2009 Can that be done on the fly(by itself). People will be uploading there picture, picture name, and description all day, every day. So when they upload, it is automatically given a page of its own. I'm still a little confused. Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-758679 Share on other sites More sharing options...
Reaper0167 Posted February 10, 2009 Author Share Posted February 10, 2009 bump ttt Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759220 Share on other sites More sharing options...
Reaper0167 Posted February 10, 2009 Author Share Posted February 10, 2009 i found this little bit of code <?php <html> 2 <head> 3 <title>My page title</title> 4 </head> 5 <body> 6 7 <img height="125" width="125" alt="Flower" src="flower01.jpg" /> 8 9 </body> 10</html> ?> Each picture will need a page like this, and then echo out the php page on my search results page????? How can this be done with all the images in the database? Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759252 Share on other sites More sharing options...
genericnumber1 Posted February 10, 2009 Share Posted February 10, 2009 This is the reason it's not very efficient to store images in a database. You could create a separate page that retrieves the image from the database based upon a GET id. Eg. <img src="image.php?id=12345" /> Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759258 Share on other sites More sharing options...
Reaper0167 Posted February 10, 2009 Author Share Posted February 10, 2009 There are different types of files in the db.... gif, bmp, png, etc. So would this line be changed or removed? header('Content-type:image/x-png'); <img src="image.php?id=12345" /> <---| Could you explain the line above please---^ Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759266 Share on other sites More sharing options...
genericnumber1 Posted February 10, 2009 Share Posted February 10, 2009 If you don't really understand much about storing image files in a database, you should do some googling. Explaining every detail would be spending a lot of time repeating what hundreds of other people have already said elsewhere. Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759273 Share on other sites More sharing options...
Reaper0167 Posted February 10, 2009 Author Share Posted February 10, 2009 storing them I do know about. What I want to do I can't find anywhere. So thanks. Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759304 Share on other sites More sharing options...
gizmola Posted February 10, 2009 Share Posted February 10, 2009 I don't think you understand what you've been told. A browser understands http protocol. In reference to html, the browser supports the rendering of html documents. Documents can have embedded elements like images, but the base html for those images is the img tag. The img tag needs to reference a source for the image --- namely a seperate url that indicates where the image can be located in web space. The client is responsible for integrating all the elements referenced in the html page and rendering them. So -- no you can't just read a blob out the database and display that. What you *can* do, is have a script that reads the image blob data from the database and returns that with the appropriate Mime header, as genericnumber1 suggested. You can then use the call to that script in a page. So--- you need to write a script that returns ONE image. The simplest manner would be using the get param as he illustrated. Let's say that the script is called: image.php. It would accept an image id, or something that can be used to find the data in the mysql database. You'd call it with : http://yoursite.com/image.php?id=5 Working properly, this should render the image in your browser. Once this is working, it's easy enough to have a page with as many images as you need: Image one! Image two! etc. Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759310 Share on other sites More sharing options...
Reaper0167 Posted February 11, 2009 Author Share Posted February 11, 2009 So are you saying that every time someone uploads a picture, i need to edit that php file? I hope not. Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759417 Share on other sites More sharing options...
genericnumber1 Posted February 11, 2009 Share Posted February 11, 2009 That's not what he's saying. Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-759456 Share on other sites More sharing options...
gizmola Posted April 21, 2009 Share Posted April 21, 2009 So are you saying that every time someone uploads a picture, i need to edit that php file? I hope not. No. The script example I provided assumed a generic script. We don't have any information from you about your database structure, so the best we can do is hypothesize. Often people use AUTO_INCREMENT to provide a numeric primary key on the table. My example assumed such a mechanism. I could easily write a script that would query the image table, and provide a list of the file names and the images. This would be "generic" in that the next time someone uploaded an image it would be reflected in the list. We don't know what the application is or what you are trying to do. You haven't provided any code to look at. We're just guessing at this point. Link to comment https://forums.phpfreaks.com/topic/144561-php-mysql-search-engine/#findComment-815698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.