0

I am very new to programming. I did research answers for this but couldn't get it sorted out. I want members of my website to be able to post comments (into a chat) that have the option of text and/or picture upload. The text part is working fine, but I'm not getting pictures to display.

<?php
if(isset($_POST['submit']))
{
$name = $_FILES['file']['comment2'];
$temp = $_FILES['file']['tmp_name'];
move_uploaded_file($temp,"uploadedpics/".$name);
echo $handle;
echo '<img src="uploadedpics/".$name />';
}
?>

<?php
date_default_timezone_set("America/New_York");

if($_POST){
$content = test_input($_POST["comment"]);
$content2 = test_input($_POST["comment2"]);
$handle = fopen("comments.html","a");
fwrite($handle,"<b>" . $profile_username . "</b>:<br/>" . $content . "<br/>" 
. $content2 . "<br/>" . date("h:i:a m-d-Y") . "<br/>" );
fclose($handle);
echo '<img src="uploadedpics/".$name />';
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<h2>let's chat, fellow remix galleryers!</h2>
<p><span class="error">* required field.</span></p>
<form action="my-profile.php" method="post" enctype="multipart/form-data"> 
<fieldset>
<div class='container'>
 Comment: <textarea name="comment" rows="5" cols="30"><?php echo $handle;?>
          </textarea>
</div>           
<div class='container'>
 Photo: <input type="file" name="comment2" id="file" accept="image/*"/>

</div>
<div class='container'>
       <input type="submit" name="submit" value="Submit"/>
</div>
</fieldset>
</form>
<?php include "comments.html"; ?>
  • `comment2` != `file`. and `$_FILES['file']['comment2']` failed. Not the way it's done. Go back to the official manuals on php.net. http://php.net/manual/en/features.file-upload.post-method.php – Funk Forty Niner Jun 13 '17 at 21:38
  • And what will happen if I upload `delete.php` with the code `` and then just browse to `http://www.yourwebsite.com/uploadedpics/detele.php`? Are you gonna complain your website is hacked? – icecub Jun 13 '17 at 21:43

0 Answers0