Results 1 to 5 of 5

Thread: simple document upload addon?

  1. #1
    Join Date
    Feb 2008
    Posts
    11

    Default simple document upload addon?

    is there a way to upload documents for agents to view in the admin area?

    here is what they want...

    a simple page to upload a document and give it a name (which would most likely be the address of the property).

    Then have a page to view all the documents they have uploaded, by the name they gave it.

    im guessing the name they create could be the link to the file?

    can anyone steer me towards how i can begin this process?

    i have seen the file upload addon by revive, but when our listings go "pending" they are no longer a listing on our site, thus can not associate documents to them...

  2. #2
    Join Date
    Feb 2008
    Posts
    11

    Default Re: simple document upload addon?

    ok, after some investigation and research i got part 1 of my project down...

    i have an addon that can upload documents to a table in my OR database...

    via this:

    Code:
      
    if(isset($_POST['upload']))
       {
        $nhm_associate = $_ POST['nhm_associate'];
        $address = $_ POST['address'];
        $fileName = $_FILES['userfile']['name'];
        $tmpName  = $_FILES['userfile']['tmp_name'];
        $fileSize = $_FILES['userfile']['size'];
        $fileType = $_FILES['userfile']['type'];
      
      $fp = fopen($tmpName, 'r');
      $content = fread($fp, $fileSize);
      $content = addslashes($content);
      fclose($fp);
      
      if(!get_magic_quotes_gpc())
      {
       $fileName = addslashes($fileName);
      }
      
      $sql = "INSERT INTO documentupload (nhm_associate, address, name, size, type, content)
         VALUES ('$nhm_associate', '$address', '$fileName', '$fileSize', '$fileType', '$content')";
      $recordSet = $conn->Execute($sql);
      
      // IF ERROR, DISPLAY A LOG TO THE PAGE
        if ($recordSet === false) {
         $misc->log_error($sql);
         }
      
      $display.= "<table width='100%'>
          <tr>
           <td><h2>File $fileName has been successfully uploaded.</h2></td>
          </tr>
         </table>";
    }
        
         // DISPLAY THE FORMS TO THE PAGE
      
      $display .= '
       <form method="post" enctype="multipart/form-data">
        <table width="650" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>NHM Associate:</td>
                        <td><select name="nhm_associate" id="nhm_associate">
          <option value="N/A" selected>NHM Associate</option>
          
         </select></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>Property Address: </td>
                        <td><input name="address" type="text" id="address"></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td><input name="userfile" type="file" id="userfile"></td>
                        <td><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
        
        <input type="hidden" name="MAX_FILE_SIZE" value="5000000">
        
      </form>';
    now i am trying to display the file in a <a href> to click on and re-download the document when they want to view....

    and here is what i have so far which is not working....its 2 more parts:


    This is the display page, that shows any records taht are in the table, and displays them as a link to download by the address name, the input on the previous form.
    Code:
     // SELECT A COLUMN NAME FROM A TABLE:
        $sql = 'SELECT * from documentupload WHERE nhm_associate="Joe Grubiak" ORDER BY address';
        // EXECUTE
        $recordSet = $conn->Execute($sql);
        // CHECK IF ERROR
        if ($recordSet === false) {
        $misc->log_error($sql);
        }
        // KEEP READING TILL THE END
        while (!$recordSet->EOF) {
        // ASSOCIATE THE FIELD VALUE WITH A VARIABLE
        $id = $misc->make_db_unsafe ($recordSet->fields['id']);
        $reg_assoc = $misc->make_db_unsafe ($recordSet->fields['nhm_associate']);
        $reg_address = $misc->make_db_unsafe ($recordSet->fields['address']);
        $reg_name = $misc->make_db_unsafe ($recordSet->fields['name']);
        $reg_size = $misc->make_db_unsafe ($recordSet->fields['size']);
        $reg_type = $misc->make_db_unsafe ($recordSet->fields['type']);
        
        
        // PREPARE TO PRINT
        $display .= '<br /><table style="width:750px; height:40px; background-image:url(http://www.newhomemarketplace.com/images/contact_tab.gif); background-position:left; background-repeat:no-repeat; border-bottom: 3px solid #987F47;">
            <tr>
             <td style="width:200px; text-align:center;"> <a href="javascript:;" onclick="toggleDiv(' . $id . ');">' . $reg_address . '</a></td>
             <td style="width:250px;">Document Summary Goes Here</td>
             
            </tr>
           </table>';
           
        $display .= '<div id="' . $id . '" style="display: none;">
          <table style="width:750px; background-color:#E1DEC6;" cellpadding="3" cellspacing="3">
           <tr>
           <td style="width:200px;">Document(s):</td>
           <td><a href="index.php?action=addon_leadstable_displayfile&id=' . $id .'">' . $reg_name .'</a></td>
            </tr>
            </div>';
    the page above calls this page, which is where the problem is....it just seems to not be able to pull the PDF document that is in the table.

    Code:
       $id=$_ GET['id'];
       if ($id == "") {
       $display .= 'No record ID identifier';
       }
       else{
         
         $sql = "SELECT * FROM documentupload WHERE id = '$id'";
         
         $recordSet = $conn->Execute($sql);
          // CHECK IF ERROR
          if ($recordSet === false) {
          $misc->log_error($sql);
          }
         list($name, $type, $size, $content) = mysql_fetch_array($recordSet);
         
         header("Content-length: $size");
         header("Content-type: $type");
         header("Content-Disposition: attachment; filename=$name");
         echo $content;
         
         
         exit;
       }
    if anyone could lend assistance, i would greatly appreciate it.

  3. #3
    Join Date
    Jul 2003
    Location
    California
    Age
    42
    Posts
    4,229

    Default Re: simple document upload addon?

    Might want to just wait till the 2.5 version of Open-Realty is released, there is already file uploads built into it.
    Open-Realty 2 Documentation

    ~The Difference Between an ORDEAL and an ADVENTURE is ATTITUDE~

  4. #4
    Join Date
    Feb 2008
    Posts
    11

    Default Re: simple document upload addon?

    i wish i could...

    it was told to me they need this ASAP...

    so im still kickn code around...

  5. #5
    Join Date
    Dec 2006
    Posts
    317

    Default Re: simple document upload addon?

    why not check out the code from svn and have a look at that? I know it is not marked as stable yet but I don't see any reason why you cannot use that. I tried on my localhost and it seems to be working without a glitch. It would be easier to follow up on the upgrades as well.

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
  •