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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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