0

I have a PHP page that opens a jQuery dialog like:

$( "#editdialog" ).dialog({
  autoOpen: false,
  title: 'Show photo',
  height: 750,
  width:900,
  modal:true
});


$( ".editer" ).click(function() {
    $( "#editdialog" ).load("photo_view.php");
    $( "#editdialog" ).dialog( "open" );
    $('.ui-widget-overlay').css('background', 'silver');
});

The load_photo.php code is the following:

$sql = "SELECT PHOTO FROM USERS WHERE ID='01'";
$result = mysql_query($sql);
if($result==FALSE) die("error".mysql_error());
$row = mysql_fetch_assoc($result);

header("Content-type: image/jpeg");
echo $row['PHOTO'];

If I browse directly to load_photo.php the image is shown. If I load the load_photo.php page inside a dialog, the image is not shown.

It can be an error of the header() function?

EDIT: I add an intermediate page like your suggestions. Now the dialog loads photo_view.php and its code is:

 <img src="load_photo.php" width="75" height="75" style="padding:0px;" class="imageborder" onerror="this.src='noimg.jpg'" accept="image/*" />

Still not working, same result. In the dialog the img box still remain blank, browsing directly to photo_view.php the image is shown.

Thank you!

DearS
  • 182
  • 2
  • 11
  • 3
    needs to be in an `` tag. Can't dump raw image data directly into the middle of an html document – charlietfl Feb 10 '16 at 14:54
  • Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Feb 10 '16 at 14:54
  • Consider accepting an answer if it answers your question! thanks – Positivity Feb 20 '16 at 22:46

1 Answers1

0

Yes the problem is that your making an image response (binary) and the browser shows it because it automatically puts it in an img tag.

You should remove header() and respond with this html code:

echo '<img src="' . $row['PHOTO'] . '">';
Positivity
  • 5,406
  • 6
  • 41
  • 61