Results 1 to 7 of 7

Thread: comment with attachment

  1. #1
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default comment with attachment

    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.

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    PHP Code:
    <?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
    Last edited by thetestingsite; 08-13-2009 at 03:18 AM.
    - Josh

  3. The Following User Says Thank You to JShor For This Useful Post:

    auriaks (08-14-2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

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

  5. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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 Code:
    <?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.

  6. #5
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    PHP Code:
    </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

  7. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    ooo hah i didnt even look at your html you have to close that <textarea name="comment"></textarea>

  8. The Following User Says Thank You to bluewalrus For This Useful Post:

    auriaks (08-14-2009)

  9. #7
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    PHP Code:
    <?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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •