Log in

View Full Version : comment with attachment



auriaks
08-12-2009, 02:34 AM
hi. I want to create comment with attachment page witch saves comment and file in my database.(site) And when someone writes comment, adds file and sends - he can see the comment and attachment in other page.
I know how to make upload and comment... but how them make work together?? PLS, add some script... Many thanks. :)

JShor
08-12-2009, 02:23 PM
<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(isset($_POST[comment])) {

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo '<font color="Green">Comment &amp; File Successfully Uploaded</font>';
echo '
<img src="'.basename( $_FILES['uploadedfile']['name']).'" alt=" Uploaded Image ">
<p>
<b>Comment:</b>
<p>'.$_POST[comment].'
<hr>';
} else {
echo "There was an error uploading the file, please try again!";
}


} else {

?>
<h1>Post Comment</h1>
<p>

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<table>
<tr>
<td>File to Upload:</td>
<td><input name="uploadedfile" type="file"></td>
</tr>
<tr>
<td>Comment:</td>
<td><textarea name="comment"></td>
</tr>
</table>
<input type="submit" value=" Add Comment ">
<input type="reset" value=" Reset ">
</form>
<?php

}

?>


HTH:)

auriaks
08-12-2009, 11:32 PM
something is wrong... i can add a picture of it, if you want. I have everythig good until "<font color="Green">", then it shows all the script as text. i can add only pictures??

bluewalrus
08-13-2009, 01:57 AM
Single quotes are not interrupted. This assumes you are uploading an image also. Change the img tag line to this if you want it to just display the file name:
<span>The file <?php echo basename( $_FILES["uploadedfile"]["name"]) ?> is on the site.</span>
in place of this :<img src="<?php echo basename( $_FILES["uploadedfile"]["name"]) ?>" alt=" Uploaded Image " />
I didn't test this so post back if it doesn't work and what the error is.

<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES["uploadedfile"]["name"]);
if(isset($_POST["comment"])) {

if(move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $target_path)) {
?>
<span style="color:#00FF00;">Comment &amp; File Successfully Uploaded</span>';
<img src="<?php echo basename( $_FILES["uploadedfile"]["name"]) ?>" alt=" Uploaded Image " />
<p>
<b>Comment:</b><br />
<?php echo $_POST["comment"] ?>
</p>
<hr />
<?php
} else {
?>
<p>There was an error uploading the file, please try again!</p>
<?php
}
} else {
?>
<h1>Post Comment</h1>
<p>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<table>
<tr>
<td>File to Upload:</td>
<td><input name="uploadedfile" type="file"></td>
</tr>
<tr>
<td>Comment:</td>
<td><textarea name="comment"></td>
</tr>
</table>
<input type="submit" value=" Add Comment ">
<input type="reset" value=" Reset ">
</form>
<?php
}
?>

Try this out.

auriaks
08-13-2009, 04:20 AM
</td>
</tr>
</table>
<input type="submit" value=" Add Comment "/>
<input type="reset" value=" Reset "/>
</form>
thats is written inside my comment textarea... why it happened?
And thats also the reason why i cant see my add and reset buttons :D

bluewalrus
08-13-2009, 05:12 PM
ooo hah i didnt even look at your html you have to close that <textarea name="comment"></textarea>

auriaks
08-14-2009, 02:47 AM
<?php

// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);


//Checking
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
header("location:mat_up_yes.php");
} else{
header("location:mat_up_no.php");
}
?>
It's now working.. That is how i stored file without comment, before... how to store and check my file and comment now? because i want to see what i add in other page. Thanks.