|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
PHP5 - Image display from mysql using php
i want to display image from mysql using php.
i uploaded file to db corectly. header("Content-Disposition: inline; filename=$trend_file_name"); i can get pdf file correctly,but can't get jpeg files.i don't identify the problem .......help me plz |
|
#2
|
|||
|
|||
|
What is it doing / not doing? Please be more specific.
A JPEG file of course, has the mime type "image/jpeg". Did you properly store the mime type and are using header() with the 'Content-type' header to output that? What about the file size ('Content-length')? Are you storing the files in at least a MEDIUMBLOB type field? Can you show us the relevant code?
__________________
BookMooch.com : Give books away. Get books you want. |
|
#3
|
||||
|
||||
|
Setting aside for the moment the fact that storing files in the database is inadvisable, the content type is the most important header to send in this case. In many cases cache control headers are also necessary. A good reference for this is the PHP manual page for header(), don't forget to read the comment section.
__________________
"Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony! Well, but you can't expect to wield supreme executive power just 'cause some watery tart threw a sword at you! I mean, if I went 'round saying I was an emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!" |
|
#4
|
|||
|
|||
|
if((isset ($_FILES['trend_file']['name']) && is_uploaded_file($_FILES['trend_file']['tmp_name'])))
{ $fileName = $_FILES['trend_file']['name']; $tmpName = $_FILES['trend_file']['tmp_name']; $fileSize = $_FILES['trend_file']['size']; $fileType = $_FILES['trend_file']['type']; $fp = fopen($tmpName, 'r'); $content_file = fread($fp, filesize($tmpName)); $content_file = addslashes($content_file); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $grpfil=mysql_query("update `property_trend` set `trend_file_size`='$fileSize',`trend_file_type`='$fileType',`trend_file_name`='$fileName',`trend_fil e`='$content_file' where `trend_id`='$filepathid'") or die("111"); } i used for uploading image ************************************************** $select_doc=mysql_query("select `trend_file_size`,`trend_file_type`,`trend_file_name`,`trend_file` from `property_trend` where `trend_id`='$trend_id' "); $row = mysql_fetch_array($select_doc); $trend_file=$row['trend_file']; $trend_file_name=$row['trend_file_name']; $size =$row['trend_file_size']; $type=$row['trend_file_type']; header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: inline; filename=$trend_file_name"); echo $trend_file; ******************************************' this code for dispaly .. this the code am using. trend_file_type value is image/jpeg and trend_file type is mediumblob ............... Any hope? i want to display this image on html page ,not for downloading.... Quote:
|
|
#5
|
||||
|
||||
|
Quote:
How are you linking to this file in order to display the image? <img src="getTrendImage.php?tend_id=4" /> Is it just trying to download the image instead of display it in the browser? If you go ahead and download it, does it open properly in an image program (ie is it a valid image)?
__________________
Spidermonkey Tutorial http://www.aoeex.com/gmap.php - Put yourself on the map |
|
#6
|
||||
|
||||
|
Quote:
addslashes() is very insecure, you will probably need to base64 encode that data, but since I would never store such data in a database, I'm not certain of that. You also escape the data twice if magic_quotes is not enabled, which makes no sense. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > PHP5 - Image display from mysql using php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|