By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Obtaining file attribute - title, PDF, Word, Excel

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I use this to find file types.

$pdf_filenames = array();
$potential_pdf = explode(".pdf", $fileName);
if (count($potential_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.

Jul 17 '05 #2

P: n/a

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.application")
or die("unable to instantiate MSWord");

....OR...

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

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

$objDocProps =
$objOfficeApp->ActiveDocument->BuiltInDocumentProperties();
....OR...
$objDocProps =
$objOfficeApp->ActiveWorkBook->BuiltInDocumentProperties();

$count = $objDocProps->count();

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

unset($objDocProp);
unset($objDocProps);

$objOfficeApp->ActiveDocument->Close();
....OR...
$objOfficeApp->ActiveWorkBook->Close();
$objOfficeApp->Quit();
unset($objOfficeApp);

?>

---
Steve

Jul 17 '05 #3

P: n/a
Thanks, Steve -

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

Jennlee2
Steve wrote:
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.application")
or die("unable to instantiate MSWord");

...OR...

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

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

$objDocProps =
$objOfficeApp->ActiveDocument->BuiltInDocumentProperties();
...OR...
$objDocProps =
$objOfficeApp->ActiveWorkBook->BuiltInDocumentProperties();

$count = $objDocProps->count();

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

unset($objDocProp);
unset($objDocProps);

$objOfficeApp->ActiveDocument->Close();
...OR...
$objOfficeApp->ActiveWorkBook->Close();
$objOfficeApp->Quit();
unset($objOfficeApp);

?>

---
Steve


Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.