Jump to content

making an echo statement a variable


bruckerrlb

Recommended Posts

Hello, I have a form, where the user uploads images, this works fine, but once the image is uploaded I would like to have the page refreshed with the specific image that the user uploaded. I have it set up so that when the user uploads the image, it goes into a specific folder, like so

 

 move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];

 

So my question is how can I  get the image to show up in the user section so that they can see what image they've just uploaded.

Link to comment
https://forums.phpfreaks.com/topic/79424-making-an-echo-statement-a-variable/
Share on other sites

You can open and close php wherever you wish on a page.

 

So therefore lets say your page looks something like this...

 

<?php
//Here is all of your php code
?>
<html>
<head>
</head>
<body>

<?php echo "<img src=\"uploads/{$_FILES['file']['name']}\" />\n"; ?>

</body>
</html>

 

You can open and close the php tags pretty much anywhere you wish on a page and call previous variables/arrays.

 

I hope this helps.

Use CSS

 

Thanks, just one more question, I have all of this code above the html tags of my page, because it's a server submit, and I am wondering how I can echo this down to the specific area of the web page i'd like it to go to

Thanks, I understand the gist of it, but when I put the echo statement below the html code, it doesn't seem to show up.

 

I have something like this

 

move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
  $filepath = $_FILES["file"]["name"];
      echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
  echo "<div class\"imgdynamic\"><img src=\"uploads/$filepath\" /></div>";

 

What i'd like to do is move it into this section

 

<p>	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
				<label for="file">Filename:</label>
					<input type="file" name="file" id="file" /> 
						<br />
					<input type="submit" name="submitvideo" value="add image" />
			</form>

		</p>
<!--right here under the code -->

 

When I put the echo statement there, no image showed up, and I suppose it's because I have an end statement, and I would normally just keep the statement open until I absolutly need to close it, but I can't keep it open because I have other php i'm trying to call, such as

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">

 

And I do believe that if I keep the statement open i'll give myself an infinite loop, which I fear.

 

I have tried using css, but it still doesn't seem to show up where I need it.

 

I appreciate the answers I am getting great feedback!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.