Find out page numbers of Ppt files with php - php

I want to get the page numbers of ppt files.
My Code:
$filename = "aaa.ppt";
$word = new COM("Powerpoint.Application");
$word->PresentationDocument->Open($filename);
$wdStatisticPages = 2; // Value that corresponds to the Page count in the Statistics
echo $word->ActivePresentation->SlideParts->Count($wdStatisticPages);
$word->ActivePresentation->Close();
$word->Quit();
But it gives error:
Fatal error: Uncaught exception 'com_exception' with message 'Unable
to lookup `PresentationDocument': Unknown name. '

This is kind of issue is due to the following factors.
PHP.ini settings
File/ Folder Permission
allow open is not enabled in the server
allowed upload size

I got the answer, thanks Suyog for your efforts.
$filename = "aaa.ppt";
$power = new COM("Powerpoint.Application");
$power->visible = True;
$power->Presentations->Open(realpath($filename));
echo $power->ActivePresentation->Slides->Count;
//$word->ActiveDocument->PrintOut();
$power->ActivePresentation->Close();
$power->Quit();

Related

PHP Fatal error: Undefined class constant 'WRITE_SCOPE'

I use PHP app in Google appengine,
I'm trying to read a input file and write it to an output file in Storage bucket like below.
$input_file = fopen('gs://mybucket/input.csv','r');
$output_file = fopen('gs://mybucket/output.csv', 'w');
And trying to write some date like
while(!feof($input_file)) {
$csv = fgetcsv($input_file,1024);
if(!$csv[0]){
fclose($output_file); //Close the connection when the loop ends
fclose($input_file);
exit(0);
}
fwrite($output_file, $csv[0]."\r\n");
}
It works perfectly, When i try to upload some data in to input file and it successfully write in to output.csv as well. but if i try more than 5 or 6th time it starts to throw an error in appengine logs like below. Any help to troubleshoot this issue will be highly appreciated!
2015-04-08 21:31:29.006 PHP Fatal error: Undefined class constant 'WRITE_SCOPE' in /base/data/home/runtimes/php/sdk/google/appengine/ext/cloud_storage_streams/CloudStorageWriteClient.php on line 214
Update:
I think this is because of opening 2 file streams at same time,
Did some work around and solved this!
$input_file = fopen('gs://mybucket/input.csv','r');
$array_acc = array();
while(!feof($input_file)) {
$csv = fgetcsv($input_file, 1024);
if($csv[0]) array_push($array_acc, $csv[0]);
}
fclose($input_file); //close the file
$acc_count = count($array_acc);
$output_file = fopen('gs://tool-synclio/output.csv','w'); // Open the output file now
while($acc_count > 0){
fwrite($output_file,$array_acc[$acc_count]."\r\n");
$acc_count --;
}
fclose($output_file);
But, I'm still waiting for some one to give better solution.
You have 2 dollar signs in a variable:
fwrite($output_file, $$csv[0]."\r\n");

my gd is enabled but still the imagecreatefromstring still not working

i want to transfer image from localhost to a server using post. i have a problem on my php who catch the image here is my code:
$string = "iVBORw0KGgoAAAANSUhEUgAAAO0AAAA2CAIAAACk1ok0AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAUJSURBVHhe7Z2hVuwwEIaRSBxIBA+ARCKRSCQS
icQhkUgkj4BEIpFIHgGJRMJ/T+6dk9uybZr8k06ys2rhJNOZf74mkzbt7nz7xxVoX4Gd9kPwCFyB
b+fYIehBAee4hyx6DM6xM9CDAs5xD1n0GJxjZ6AHBZzjNrL4/Px8enr6+PjYhrvVvVyfY+Tm8PBw
J/rgT6WEPT09hWPpHUIpgwcHB3B7d3c3wz7OgYHCsdqWv6enaU2OxwSLpnkJm87xx8cHzKoeIgOy
2S5vb2+Xl5fi9mz7cYNGIQ4hJ5JQm+PEseHq6iojYXGXz8/P29vbiRSWH6LQw9nuLy8vA/8vLi5m
e40b3N3dWR50p31LTFM9jl9fX+/v78P8OPggPV9fXxkZ+rULBrDr6+u9vb1NAqG6YB1Lz85g9kAs
Z2dnRJW4npdMFxRPFDlGJkDMzc0NFiibkDo6OirMTeIALw6ABopwqkYwmeDcDj7jzMeYhLFZ9YiF
xjvkeBFYhfKh+0TlkL5KKHeDaOHh4SGeTOzPHhiwOuR4E1j4P8YYlBYoMIhhj4u/JgawTdyjpo/n
riZmD1Rxwefj42Pi+bzIFL+uiMFCRYG6AiMKTtnYLSLHMNvNtVWMxKJMQ5OJrHlWnDr4HKecRlyO
S66tpnhbrY0AYXlJN1aDm808tXvg2IKOeeoPekkghWtfijPpRizovwLHuC7GjZxrLT1/9JaNBmLB
7docY6TBaiBEjuqZgoIFHbc5EAv61+ZY1uO43/j+/r7N6bdZaGZkZBs5lqUMLmtkSPZrFws6UmJp
NBALbtcejzVi1rBJ4XKpkRYDQaFowW3neClsiu0tALE0PGxaDG7jgvfSvsT2zjFRzFJTLXJ8cnIS
3CYWihk6OscZov3tEm8Npdx+a45juYSKVfvglm2+rFk9u+JYOFjlS+KO74k0Ncex7Kw4Pz/Pwo/W
yTmmMZ+447snjmVfHra40JDMMuQcF3FMKSckcc2Nx3Yc7orjrDPZUCc7WCSKYsdh5zgxZTWayWOw
uOtZ43jFx3COmeePHTULwZBl0+qXsVICwaNWFq4cB1eZPKUEr8Gchs2UWOhtcG8MO49DOOVXP+ju
DQxiXRtcxaMS2seate8cz0pUtYGR27wpMctWGTyoltJetY1zrCpvjnGZXpReqpTj0299TE2DzjEr
rTQ7strDF8soO8d/FKClHTX+vw/R5oqm4gd1LVfJpmRn8jSbe6UVrilBZ0VIaRCjnNJ+lTamZK/K
sdIK15SgLKSkusBeHJZNrh1TslflWGmFa0pQFivyXqzVt+BsisiU7FU5VopcySyLyDw78VPl627t
dY6HCigBp2Q2jz9iL3ntsc3VninZfTwmgjdjavYNjtg9F79a0/g9EeeYfPKYEnSC5ZL3wtc725KP
ZEp2MlLTIihFLkt7m3WkaFLyXniDLxFVymbyefRfwx44lm1iNuvI9MSEN+nv7+8LIrNfuBv5011F
S+eYfPIYryMXwYHGGeXHKjQ7x2SOrY0NS8EdtB+XH1j8haF6AvH6c9H2ciyFbGGmx92be5KCokBM
fPlTrktd2l6Og+4aisdPUrTyUNBSbqy1316O9TIRP0kR9MUUDLjpLwfp5jccynOhN7tm+MYvVTOc
oHQZozy72M9uUL8YpUjENaI3u2b42Q/HCB4oxz9hm41pSscMrb2LngJdcRzLhN8Okhffp3C5qI1G
ia+X422w/AO/8BouFT8hjwAAAABJRU5ErkJggg==";
that $string is my sample image
$img2 = base64_decode($string);
$img = imagecreatefromstring($img2);
if($img != false)
{
//this is the location and name you can use date time to create name if you want
//also put the path before the image if you want to save it to a folder ex. 'pics/image.jpg'
$path = "sample_upload/images/" . date("Y_m_d_H_i_s") . ".jpg";// put path here
$sampledate = date("Y_m_d_H_i_s");
echo $sampledate;
imagejpeg($img, $path.''.$sampledate.'.jpg');
//they can put db query here if they like to insert img path and email
}
the error is [31-Aug-2013 13:56:49 Asia/Manila] PHP Fatal error: Call to undefined function imagecreatefromstring()
the php version should be higher than 5

typo3 captcha error

Since a few days the captcha image doesn't show up anymore.
I when i try to reach the captcha.php the file gives me an error:
Fatal error: Class 't3lib_div' not found in /typo3conf/localconf.php on line 10
When I lookup the localconf.php file, the first 20 lines look like this:
<?php
$TYPO3_CONF_VARS['SYS']['sitename'] = 'New TYPO3 site';
// Default password is "joh316" :
$TYPO3_CONF_VARS['BE']['installToolPassword'] = 'bacb98acf97e0b6112b1d1b650b84971';
$TYPO3_CONF_VARS['EXT']['extList'] = 'tsconfig_help,context_help,extra_page_cm_options,impexp,sys_note,tstemplate,tstemplate_ceditor,tstemplate_info,tstemplate_objbrowser,tstemplate_analyzer,func_wizards,wizard_crpages,wizard_sortpages,lowlevel,install,belog,beuser,aboutmodules,setup,taskcenter,info_pagetsconfig,viewpage,rtehtmlarea,css_styled_content,t3skin';
$typo_db_extTableDef_script = 'extTables.php';
// MAX FILE SIZE
$TYPO3_CONF_VARS['BE']['maxFileSize'] = '100000';
t3lib_div::loadTCA('tt_content');
// This changes the upload limit for image elements
$TCA['tt_content']['columns']['image']['config']['max_size'] = 100000;
// This changes the upload limit for media elements
$TCA['tt_content']['columns']['media']['config']['max_size'] = 100000;
// This changes the upload limit for multimedia elements
$TCA['tt_content']['columns']['multimedia']['config']['max_size'] = 100000;
Does anybody has an idea why I get this error?
The best would be that this settings below would be in ext_tables.php file of some extension.
But if you don't have any special ext for that then you can put that into typo3conf/extTables.php file. After that the error about t3lib_div not found should be gone.
// MAX FILE SIZE
$TYPO3_CONF_VARS['BE']['maxFileSize'] = '100000';
t3lib_div::loadTCA('tt_content');
// This changes the upload limit for image elements
$TCA['tt_content']['columns']['image']['config']['max_size'] = 100000;
// This changes the upload limit for media elements
$TCA['tt_content']['columns']['media']['config']['max_size'] = 100000;
// This changes the upload limit for multimedia elements
$TCA['tt_content']['columns']['multimedia']['config']['max_size'] = 100000;

Pass Date Parameter From PHP to Crystal Report

I am having substantial trouble passing a date parameter to the Crystal Reports 11 component from PHP5 on Windows. It should be easy, of course, but the various commented-out items don't seem to work:
<?php
$my_report = "C:\\xampp\htdocs\wincare\laporan\adm_JumlahPasienPoli.rpt"; // rpt source file
$my_pdf = "C:\\xampp\htdocs\wincare\laporan\adm_JumlahPasienPoli.pdf"; // RPT export to pdf file
//-Create new COM object-depends on your Crystal Report version
$ObjectFactory= new COM("CrystalReports115.ObjectFactory.1") or die ("Error on load"); // call COM port
$crapp = $ObjectFactory-> CreateObject("CrystalDesignRunTime.Application.11"); // create an instance for Crystal
$creport = $crapp->OpenReport($my_report,1); // call rpt report
// to refresh data before
//- Set database logon info - must have
$creport->Database->Tables(1)->SetLogOnInfo("localhost", "db_wincare", "sa", "sa");
//- field prompt or else report will hang - to get through
$creport->EnableParameterPrompting = 0;
// this is the error
$zz = $creport->ParameterFields(1)->SetCurrentValue("2011-01-01 00:00:00");
//export to PDF process
$creport->ExportOptions->DiskFileName=$my_pdf; //export to pdf
$creport->ExportOptions->PDFExportAllPages=true;
$creport->ExportOptions->DestinationType=1; // export to file
$creport->ExportOptions->FormatType=31; // PDF type
$creport->Export(false);
//------ Release the variables ------
$creport = null;
$crapp = null;
$ObjectFactory = null;
//------ Embed the report in the webpage ------
print "<embed src=\"adm_JumlahPasienPoli.pdf\" width=\"100%\" height=\"100%\">"
?>
and the messege :
Fatal error: Uncaught exception 'com_exception' with message
'Source: Description: ' in
C:\xampp\htdocs\wincare\laporan\pakai.php:36 Stack trace: #0
C:\xampp\htdocs\wincare\laporan\pakai.php(36):
variant->SetCurrentValue('2011-01-01 00:0...') #1 {main} thrown in
C:\xampp\htdocs\wincare\laporan\pakai.php on line 36
I remember spending a long time on this question some five years ago, and eventually finding a hacky but working answer:
// This block is strictly guesswork
$application = new COM("CrystalRuntime.Application.9"); // Change to your version
$report = $application->OpenReport($my_report,1); // From OP's code
$rptParams = $report.ParameterFields
$rptParam = $rptParams->Item(2); // From my SitePoint post;
// obviously you need to use
// the right index
// Check that $rptParam->ValueType evaluates to 10 - if it does not
// then modify the type in Crystal Reports itself. Again, see my
// original solution
// This bit should be fine
$oScript = new COM("MSScriptControl.ScriptControl");
$oScript->Language = "VBScript";
$oScript->AllowUI = false;
$oScript->AddObject('rptParam', $rptParam, true);
$oScript->AddCode('Function SetDateParameter(strDate)
rptParam.AddCurrentValue(CDate(strDate))
End Function');
$oScript->Run("SetDateParameter", "25 April 2006");
This worked fine, but it's not very elegant! Worked on CR9 with Windows Server 2003, I think. Copied from here - was prior to the birth of StackExchange :).

Getting an errno 2 when running a PHP script

Hope you help me... I've been at this for the past 2 days and have to admit that I'm stumped.
The OS I'm on is Ubuntu 9.10 Karmic.
I successfully installed and tested Mapserver. For my class project, I have a php script that I am using to create a layer see below....
The error I get when run the script on a cmd line prompt:
Warning: [MapServer Error]: msProcessProjection(): no system list, errno: 2
in /var/www/mapserverdocs/ms4w/apps/world/mapscripts/staticwms.php on line 16
Warning: Failed to open map file static.map in /var/www/mapserverdocs/ms4w/apps/world/mapscripts/staticwms.php on line 16
Fatal error: Call to a member function owsdispatch() on a non-object in /var/www/mapserverdocs/ms4w/apps/world/mapscripts/staticwms.php on line 18
PHP SCRIPT:
<?php
if (!extension_loaded("MapScript")) dl("php_mapscript");
$request = ms_newowsrequestobj();
foreach ($_GET as $k=>$v) {
$request->setParameter($k, $v);
}
$request->setParameter("VeRsIoN","1.0.0");
ms_ioinstallstdouttobuffer();
$oMap = ms_newMapobj("static.map");
$oMap->owsdispatch($request);
$contenttype = ms_iostripstdoutbuffercontenttype();
if ($contenttype == 'image/png') {
header('Content-type: image/png');
ms_iogetStdoutBufferBytes();
} else {
$buffer = ms_iogetstdoutbufferstring();
echo $buffer;
}
ms_ioresethandlers();
?>
I made the directory and files world wide rwx just to make sure it was not a permissions issue
Any help would be greatly appreciated!!
Thanks
Chris
As meagar said, the issue is probably that this line:
$oMap = ms_newMapobj("static.map");
is unable to find "static.map". The current working directory of PHP is very often not what you'd expect it to be. Try making the path be relative to the current script. If static.map is in the same directory as static.map, try this code:
$mapPath = dirname(__FILE__).'/static.map';
$oMap = ms_newMapobj($mapPath);
$oMap->owsdispatch($request);
if static.map is at, let's say, /var/www/mapserverdocs/ms4w/apps/world/mapfiles/static.map, then try:
$mapPath = dirname(__FILE__).'/../static.map';
$oMap = ms_newMapobj($mapPath);
$oMap->owsdispatch($request);
Notice the */../*static.map. dirname(__FILE__) will return the name of the directory of the PHP file you place that code in.

Categories