Obtaining file attribute - title, PDF, Word, Excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jennlee2

    Obtaining file attribute - title, PDF, Word, Excel

    Hello -

    I'm trying to write something that will traverse the directory
    structure of my web server directory and pull some particular
    information on particular file types to create a listing of what all is
    where.

    For PDF files I want to find the title. I've been looking through
    php.net and the ClibPDF Functions, but I'm still not clear on how to
    find the title of an existing pdf document.

    I also want to find the titles of Word and Excel documents.

    I already have the code to traverse the directory structure.
    Thanks in advance for information!

    Jennlee2

  • Steve

    #2
    Re: Obtaining file attribute - title, PDF, Word, Excel

    I use this to find file types.

    $pdf_filenames = array();
    $potential_pdf = explode(".pdf", $fileName);
    if (count($potenti al_pdf) == 2) {
    $pdf_filenames[] = $potential_pdf[0];
    }

    There are dozens of ways to get the file name. You could also use
    regex functions as well.

    Comment

    • Steve

      #3
      Re: Obtaining file attribute - title, PDF, Word, Excel


      Um, OP wants the /document titles/ not the filenames.

      Can't help with PDFs, but for MS Excel and MS Word use the COM
      interface...

      <?php

      $objOfficeApp = new COM("word.appli cation")
      or die("unable to instantiate MSWord");

      ....OR...

      $objOfficeApp = new COM("excel.appl ication")
      or die("unable to instantiate MSExcel");

      $objOfficeApp->Documents->Open( "c:\\temp\\test .doc" );
      ....OR...
      $objOfficeApp->Workbooks->Open( "c:\\temp\\test .xls" );

      $objDocProps =
      $objOfficeApp->ActiveDocume nt->BuiltInDocumen tProperties();
      ....OR...
      $objDocProps =
      $objOfficeApp->ActiveWorkBo ok->BuiltInDocumen tProperties();

      $count = $objDocProps->count();

      while( $objDocProp = $objDocProps->Next() )
      {
      if( $objDocProp->Name() == 'Title' )
      {
      print 'Title: ' . $objDocProp->Value() . "\n";
      break;
      }
      }

      unset($objDocPr op);
      unset($objDocPr ops);

      $objOfficeApp->ActiveDocume nt->Close();
      ....OR...
      $objOfficeApp->ActiveWorkBo ok->Close();
      $objOfficeApp->Quit();
      unset($objOffic eApp);

      ?>

      ---
      Steve

      Comment

      • Jennlee2

        #4
        Re: Obtaining file attribute - title, PDF, Word, Excel

        Thanks, Steve -

        Will try this - looks like what I am looking for.

        Jennlee2


        Steve wrote:[color=blue]
        > Um, OP wants the /document titles/ not the filenames.
        >
        > Can't help with PDFs, but for MS Excel and MS Word use the COM
        > interface...
        >
        > <?php
        >
        > $objOfficeApp = new COM("word.appli cation")
        > or die("unable to instantiate MSWord");
        >
        > ...OR...
        >
        > $objOfficeApp = new COM("excel.appl ication")
        > or die("unable to instantiate MSExcel");
        >
        > $objOfficeApp->Documents->Open( "c:\\temp\\test .doc" );
        > ...OR...
        > $objOfficeApp->Workbooks->Open( "c:\\temp\\test .xls" );
        >
        > $objDocProps =
        > $objOfficeApp->ActiveDocume nt->BuiltInDocumen tProperties();
        > ...OR...
        > $objDocProps =
        > $objOfficeApp->ActiveWorkBo ok->BuiltInDocumen tProperties();
        >
        > $count = $objDocProps->count();
        >
        > while( $objDocProp = $objDocProps->Next() )
        > {
        > if( $objDocProp->Name() == 'Title' )
        > {
        > print 'Title: ' . $objDocProp->Value() . "\n";
        > break;
        > }
        > }
        >
        > unset($objDocPr op);
        > unset($objDocPr ops);
        >
        > $objOfficeApp->ActiveDocume nt->Close();
        > ...OR...
        > $objOfficeApp->ActiveWorkBo ok->Close();
        > $objOfficeApp->Quit();
        > unset($objOffic eApp);
        >
        > ?>
        >
        > ---
        > Steve[/color]

        Comment

        Working...