Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access file properties through PHP

In windows explorer their is a summary tab that contains, title, subject, author, category, keywords, and comments for every file. Is it possible to read and edit this data using php?

like image 786
James Avatar asked Nov 04 '22 18:11

James


1 Answers

You can't get meaningful metadata with PHP in windows for many applications. The only real exception for this would be using PHP's Component Object Model.

Reference

http://www.php.net/manual/en/intro.com.php

Here is an example for word / excel:

// for MSExcel use:
$objOfficeApp = new COM("excel.application") or die("unable to instantiate MSExcel");
// for MSWord use:
//$objOfficeApp = new COM("word.application") or die("unable to instantiate MSWord");

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

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

$count = $objDocProps->count();

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

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

$objOfficeApp->ActiveWorkBook->Close();
//$objOfficeApp->ActiveDocument->Close();
$objOfficeApp->Quit();
unset($objOfficeApp);
like image 74
Swift Avatar answered Nov 09 '22 03:11

Swift