0

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">

<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>
0

5 Answers 5

1

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.

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

Can't use $no outside of script block.
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?
0

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

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

Comments

0

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....

1 Comment

<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
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.