monypresents Posted August 17, 2007 Share Posted August 17, 2007 When i try to display images after uploading them to my mysql database using php, They come out distorted. Does anyone know what it going on? You can check out http://alternate-domain.com.s24240.gridserver.com/project.php?id=4 to see what i am talking about. Feel free to use the test account to mess around with it. user: monytest Pass: cypress Quote Link to comment https://forums.phpfreaks.com/topic/65501-images-get-scrambled-when-displaying-them-from-database/ Share on other sites More sharing options...
dbo Posted August 17, 2007 Share Posted August 17, 2007 Can you show us your upload script? Quote Link to comment https://forums.phpfreaks.com/topic/65501-images-get-scrambled-when-displaying-them-from-database/#findComment-327060 Share on other sites More sharing options...
monypresents Posted August 17, 2007 Author Share Posted August 17, 2007 ______________________________________________________________________________ ______________________________________________________________________________ This is the php file... "attachment.php" ______________________________________________________________________________ ______________________________________________________________________________ [code]<?php require_once('includes/config.php'); require_once('includes/functions/func.global.php'); db_connect($config); if(!isset($_GET['type'])) { $_GET['type'] = 'attachment'; } if($_GET['type'] == 'image') { $query = "SELECT provider_picture,provider_pictype FROM `".$config['db']['pre']."providers` WHERE provider_id='" . validate_input($_GET['id']) . "' LIMIT 1"; $query_result = @mysql_query ($query) OR error(mysql_error()); $rows = mysql_num_rows($query_result); if($rows == 0) { $filedata = base64_decode('R0lGODlhAQABAIAAAMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='); $filesize = strlen($filedata); header('Content-type: image/gif'); header('Content-Length: ' . $filesize); header('Connection: Close'); echo $filedata; exit; } else { while ($info = @mysql_fetch_array($query_result)) { if($info['provider_picture'] == '') { $filedata = base64_decode('R0lGODlhAQABAIAAAMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='); $filesize = strlen($filedata); header('Content-type: image/gif'); header('Content-Length: ' . $filesize); header('Connection: Close'); echo $filedata; exit; } else { header("Content-type: " . $info['provider_pictype']); echo stripslashes($info['provider_picture']); } } } } else { $query = "SELECT file_name,file_type,file_content FROM `".$config['db']['pre']."attachments` WHERE file_id='" . validate_input($_GET['id']) . "' LIMIT 1"; $query_result = @mysql_query ($query) OR error(mysql_error()); $rows = mysql_num_rows($query_result); if($rows == 0) { exit; } else { while ($info = @mysql_fetch_array($query_result)) { header('Content-type: ' . $info['file_type']); header('Content-disposition: attachment; filename="' . $info['file_name'] . '"'); echo stripslashes($info['file_content']); } } } ?> [/code] ______________________________________________________________________________ ______________________________________________________________________________ This is the HTML for the Upload page... create_project.html ______________________________________________________________________________ ______________________________________________________________________________ {OVERALL_HEADER} <SCRIPT LANGUAGE="JavaScript"> function formValidation(form) { if(notEmpty(form.project_name,"{LANG_PROJNAME}")) { if(notEmpty(form.project_description,"{LANG_PROJDESC}")) { if(notEmpty(form.days,"{LANG_BIDTIME}")) { return true; } } } return false; } function notEmpty(elem,fname) { var str = elem.value; if(str.length == 0) { alert("You must fill in the "+fname+" field."); return false; } else { return true; } } </script> <table width="780" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td valign="top"> <form onSubmit="return formValidation(this)" action="" method="post" enctype="multipart/form-data" name="form"> {LOOP: ERRORS}<span class="error">- {ERRORS.message}</span><br> {/LOOP: ERRORS} <br> <table border="0" cellspacing="0" cellpadding="4" class="normal"> <tr> <td><strong>{LANG_USERNAME}</strong></td> </tr> <tr> <td>{USERNAME}</td> </tr> <tr> <td><strong>{LANG_PROJNAME}</strong></td> </tr> <tr> <td><input name="project_name" type="text" id="project_name" size="40" maxlength="200" value="{PROJECTTITLE}"></td> </tr> <tr> <td><strong>{LANG_PROJTYPE}</strong></td> </tr> <tr> <td> <table border="0" cellpadding="0" cellspacing="0"> {LOOP: JOBTYPES} <tr><td><input name="jobtype[{JOBTYPES.id}]" type="checkbox" value="{JOBTYPES.id}"></td><td> {JOBTYPES.title}</td></tr> {/LOOP: JOBTYPES} </table> </td> </tr> <tr> <td><strong>{LANG_PROJDESC}</strong></td> </tr> <tr> <td><textarea name="project_description" cols="50" rows="9" id="textarea">{DESCRIPTION}</textarea></td> </tr> <tr> <td><strong>{LANG_ATTACHMENT}:</strong> <input name="attachment" type="file" id="attachment2" size="40"> (Max. 500 KB)</td> </tr> <tr> <td> </td> </tr> <tr> <td><strong>{LANG_BUDGET}</strong></td> </tr> <tr> <td>{LANG_MIN}: {CURRENCY_SIGN} <input name="budget_min" type="text" id="budget_min2" size="8" value="{MINBUDGET}"></td> </tr> <tr> <td>{LANG_MAX}: {CURRENCY_SIGN} <input name="budget_max" type="text" id="budget_max2" size="8" value="{MAXBUDGET}"></td> </tr> <tr> <td> </td> </tr> <tr> <td>{LANG_WANTBID} <input name="days" type="text" id="days2" size="5" maxlength="2" value="{BIDDINGTIME}"> {LANG_DAYS}</td> </tr> <tr> <td> </td> </tr> <tr> <td><input name="featured" {FEATURED} type="checkbox" id="featured2" value="1"> {LANG_WANTPAY} {CURRENCY_SIGN}{FEATURED_PRICE} {LANG_WANTFEAT}</td> </tr> <tr> <td> </td> </tr> <tr> <td><input type="submit" name="Submit" value="{LANG_SUBPROJECT}"></td> </tr> </table> </form> <br> </td> </tr> </table> {OVERALL_FOOTER} ______________________________________________________________________________ ______________________________________________________________________________ This is the HTML for the page that displays the info... project.html ______________________________________________________________________________ ______________________________________________________________________________ {OVERALL_HEADER}<table width="780" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td valign="top"><br> <span class="project_title_header"> {LANG_PROJECT}:</span> <span class="project_title"><strong>{PROJECT_TITLE}</strong></span><br> <span class="normal"><strong> {LANG_ID}:</strong> {PROJECT_ID}</span><br> <br> <table width="100%" border="0" cellpadding="4" cellspacing="3"> <tr class="normal" bgcolor="#ECECEC" valign="top"> <td width="180"><strong>{LANG_STATUS}: </strong></td> <td>{PROJECT_STATUS}</td> </tr> <tr class="normal"> <td><strong>{LANG_BUDGET}: </strong></td> <td>{PROJECT_BUDGET}</td> </tr> <tr class="normal" bgcolor="#ECECEC" valign="top"> <td><strong>{LANG_CREATED}:</strong></td> <td>{PROJECT_START_DATE} at {PROJECT_START_TIME} {PROJECT_START_TIMEZONE} </td> </tr> <tr class="normal"> <td><strong>{LANG_BIDENDS}:</strong></td> <td>{PROJECT_END_DATE} at {PROJECT_END_TIME} {PROJECT_END_TIMEZONE} </td> </tr> <tr class="normal" bgcolor="#ECECEC" valign="top"> <td><strong>{LANG_PROJCREATOR}:</strong></td> <td><a href="profile.php?id={PROJECT_CREATOR_ID}&type=buyer">{PROJECT_CREATOR_USERNAME}</a></td> </tr> <tr class="normal"> <td><strong>{LANG_RATING}: </strong></td> <td> IF("{REVIEWS}"=="0"){({LANG_NOFEEDYET}){:IF} IF("{REVIEWS}"!="0"){<a href="reviews.php?id={PROJECT_CREATOR_ID}&type=buyers"><img border="0" src="templates/{TPL_NAME}/images/rating_{RATING}.gif"><br>({REVIEWS} {LANG_REVIEWS})</a>{:IF} </td> </tr> <tr class="normal" bgcolor="#ECECEC" valign="top"> <td><strong>{LANG_DESC}:</strong></td> <td> {PROJECT_DESC}</td> </tr> IF("{ATTACHMENT}" == "1"){<tr class="normal" valign="top"><td><strong>{LANG_ATTACHMENT}:</strong></td><td><a href="attachment.php?id={FILE_ID}"><img src="attachment.php?id={FILE_ID}"></a></td></tr>{:IF} <tr class="normal" IF("{ATTACHMENT}" == "1"){bgcolor="#ECECEC"{:IF} valign="top"> <td><strong>{LANG_JOBTYPE}: </strong></td> <td> {LOOP: PROJECT_TYPES}- {PROJECT_TYPES.name}<br> {/LOOP: PROJECT_TYPES} </td> </tr> <tr class="normal" IF("{ATTACHMENT}" == "0"){bgcolor="#FFFFFF"{:IF} valign="top"> <td><strong>{LANG_DATABASE}: </strong></td> <td>{PROJECT_DB}</td> </tr> <tr class="normal" IF("{ATTACHMENT}" == "1"){bgcolor="#ECECEC"{:IF}> <td><strong>{LANG_OPSYS}: </strong></td> <td>{PROJECT_OS}</td> </tr> </table> <br> <br> <span class="normal"><a href="board.php?i={PROJECT_ID}">{LANG_VIEWMSGB}</a><br> {LANG_MESSPOSTED}: <strong>{MESSAGES}</strong></span><br> <br><br> <table width="780" cellpadding="0" cellspacing="1" border="0"> <tr> <td colspan="5"> IF("{PROJECT_STATUS2}"=="open"){<a href="bid.php?id={PROJECT_ID}"><img src="templates/{TPL_NAME}/images/button_placebid.gif" width="76" height="16" alt="" border="0"></a><br><br>{:IF} IF("{EDIT_BID}"=="1"){<a href="bid.php?id={PROJECT_ID}"><img src="templates/{TPL_NAME}/images/edit_bid.gif" width="76" height="16" alt="" border="0"></a><br><br>{:IF} </td> </tr> <tr class="normal" bgcolor="#E1E1E1" align="center"> <td width="300" align="left"><strong>{LANG_PROVIDERU}</strong></td> <td width="60"><div align="center"><strong>{LANG_BID}</strong></div></td> <td width="100"><div align="center"><strong>{LANG_DELWITHIN}</strong></div></td> <td width="136"><strong>{LANG_TIMEOFBID}</strong></td> <td width="136"><strong>{LANG_RATING}</strong></td> </tr> {LOOP: BIDS} <tr class="normal"> <td><a href="profile.php?id={BIDS.user_id}&type=provider">{BIDS.username}</a></td> <td>{CURRENCY_SIGN}{BIDS.bid_amount}</td> <td>{BIDS.bid_days} {LANG_DAYSB}</td> <td>{BIDS.bid_date} {LANG_AT} {BIDS.bid_time} {BIDS.bid_timezone}</td> <td><div align="center"> IF("{BIDS.bid_reviews}"=="0"){({LANG_NOFEEDYET}){:IF} IF("{BIDS.bid_reviews}"!="0"){<a href="reviews.php?id={BIDS.user_id}&type=provider"><img border="0" src="templates/{TPL_NAME}/images/rating_{BIDS.bid_rating}.gif"><br>({BIDS.bid_reviews} {LANG_REVIEWS})</a>{:IF} </div></td> </tr> <tr class="normal"> <td colspan="5">{BIDS.bid_desc}</td> </tr> <tr> <Td colspan="5" height="1" background="templates/{TPL_NAME}/images/hline_dot.gif"></TD> </tr> {/LOOP: BIDS} <tr> <td colspan="5"><br> IF("{PROJECT_STATUS2}"=="open"){<a href="bid.php?id={PROJECT_ID}"><img src="templates/{TPL_NAME}/images/button_placebid.gif" width="76" height="16" alt="" border="0"></a><br><br>{:IF} IF("{EDIT_BID}"=="1"){<a href="bid.php?id={PROJECT_ID}"><img src="templates/{TPL_NAME}/images/edit_bid.gif" width="76" height="16" alt="" border="0"></a><br><br>{:IF} </td> </tr> </table> <br></td> </tr> </table> {OVERALL_FOOTER} Quote Link to comment https://forums.phpfreaks.com/topic/65501-images-get-scrambled-when-displaying-them-from-database/#findComment-327099 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.