Forums

[resolved] Is it possible to search in attached files? (10 posts)

  1. hixen
    Member
    Posted 1 year ago #

    Like the topic says, is it possible to search in attached files?

    An example: I upload a filenam.doc file to the site, is it possible to have an option that says include search in attached files, and WordPress searches throuh the filename.doc and shows it's findings?

    If it's possible, can anyone point my into the right direction.

  2. hixen
    Member
    Posted 1 year ago #

    Anyone?

  3. forunner
    Member
    Posted 1 year ago #

    Bad solution, but I don't know any other.
    I don't know if WordPress can do this alone, but php can
    you have to put the result of this function into a variable, and use a function like that (I translate the code for you) :

    <?php
    /******************************************************************************/
    /*                                                                            */
    /*                       __        ____                                       */
    /*                 ___  / /  ___  / __/__  __ _____________ ___               */
    /*                / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-<               */
    /*               / .__/_//_/ .__/___/\___/\_,_/_/  \__/\__/___/               */
    /*              /_/       /_/                                                 */
    /*                                                                            */
    /*                                                                            */
    /******************************************************************************/
    /*                                                                            */
    /* Titre          : find a character in a string                      */
    /*                                                                            */
    /* URL            : http://www.phpsources.org/scripts154-PHP.htm              */
    /* Auteur         : PHP Sources                                               */
    /* Date édition   : 04 Jan 2006                                               */
    /*                                                                            */
    /******************************************************************************/
    
      $my_string = 'abcefghigkmnlopqrstuvwxyz'; // put your variable containing your .doc instead $my_string
      $find_me  = 'a'; // put the search instead $find_me
      $position = strpos($my_string, $find_me);
    
      // you have to use ===  because == won't display anything
      // because the letter 'a' is in position 0
    
      if ($position === false) {
          echo '',$find_me,' not found in ',$my_string,'';
          } else
          {
          echo '',$find_me,' in in  ',$my_string,'';
          echo 'in position ',$position,'';
          }
    
    ?>

    if the translated code don't work, try to use the original - maybe I've make a mistake.

  4. Mark / t31os
    Moderator
    Posted 1 year ago #

    I think what's being asked here is to have the search look within the documents themselves, that's not quite so simple.

    The problem with that is that you'd need to query all the files, read the contents of each file and check for the search term (that's alot of work for a script to do), so basically loop over each file, checking contents as you go (not something you can do with a query).

    http://php.net/manual/en/function.file-get-contents.php

    I'd not consider such a method to be efficient, especially if you've got more then a handful (5-10) attachments, the processing required would grow as the amount of attachments does.

    Maybe an alternative would be to tag attachments?
    http://wordpress.org/extend/plugins/media-tags/

  5. forunner
    Member
    Posted 1 year ago #

    that's why I said my solution was " a bad solution " :p

  6. Roy
    Member
    Posted 1 year ago #

    The search everything plugin has the option to search attachments.

  7. forunner
    Member
    Posted 1 year ago #

    I don't think it's for the content :p

    Search every attachment:
    (post type = attachment)

  8. Mark / t31os
    Moderator
    Posted 1 year ago #

    that's why I said my solution was " a bad solution " :p

    I wasn't meaning to imply there was a problem with your suggestion(ie. a bad suggestion), simply pointing out that it may not fully address the question asked.. ;) No harm done.. :)

    The search everything plugin has the option to search attachments.

    It won't search "in" attachments though, such as .doc files (or any other file), because (well, put simply) the content of those files is not in the database, which is where the search is looking, but good suggestion nonetheless.. :)

  9. forunner
    Member
    Posted 1 year ago #

    I wasn't meaning to imply there was a problem with your suggestion

    There is one :D

  10. hixen
    Member
    Posted 1 year ago #

    Thanks alot guys, your input was very helpfull.

    I will tag my attachments since that seems the best way, and write a short description for each file.

Topic Closed

This topic has been closed to new replies.

About this Topic