tags:

views:

69

answers:

5

i know it is so simple problem but eventually it isn't working and i am a newbie. in the index.html, a swf sends an image and displayImage.php(below code) should display it on another page. why isn't it working??

<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
$no=0;
while (file_exists("images/$no.jpg"))
     $no++;
header('Content-Type: image/jpeg');
$image = $GLOBALS["HTTP_RAW_POST_DATA"];
file_put_contents("images/".$no.".jpg", $image);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-9" />
<title>Your Image</title>
<link href= "style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="logo"></div>
<div id="body"></div>
/////////display image//////////
<img src="images/<?$no.".jpg?>"> 

</body>
</html>
A: 
<img src="images/<?=$no.".jpg"?>"> 
peelman
Can't use `$no` outside of script block.
Marcus Adams
Why can’t you? Are you referring to the while loop, which is irrelevant since he declared $no above it, or because its not inside <?php which <?= is shorthand for?
peelman
A: 

This might be the issue. The line below the "display image" comment, should probably read:

<img src="images/<?= $no ?>.jpg"> 
Nate Pinchot
+1  A: 

You don't echo the filename (and you have a quoting error, but this could be a typo):

<img src="images/<?php echo $no ?>.jpg" />

Assuming that storing the file actually works.

Felix Kling
A: 

i deleted the line "header('Content-Type: image/jpeg');" and it works!

A: 

Could be that you're using XHTML strict. IMG tags can't be unclosed like in normal HTML. You have to end it with a /> instead. (it's supposed to fail catastrophically when you make an error but it only does that when you send the right MIME type header to treat it as XML, so treated as text you may get unpredictable results.....). If it's printing the name of the file (like images/1.jpg) then you know that it's parsing the inline PHP correctly....

Billy
<img src="images/<?= $no ?>.jpg"> could work in xhtml, but it isn't. it is only printing the name of the php file. as http:// mySite.rosenhost.info/displayImage.php?name=displaySWF.jpg