com_exception with message Source: Unknown Description: Unknown IIS PHP - php

I'm using a VM deployed with windows server r2 2012 and facing an issue while converting PPT to Image using PHP COM dll on IIS8.Below is the code that I'm using
<?php
$file_path = "test_ppt_to_image.pptx";
$powerpnt = new COM("powerpoint.application") or die("");
try {
$presentation = $powerpnt->Presentations->Open(realpath($file_path)) or die("Unable to open the slide");
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";exit;
}
$i=1;
$exportFolder = realpath("test_images");
foreach($presentation->Slides as $slide)
{
$slideName = $i."_SS_";
$slide->Export($exportFolder."/".$slideName.".jpg", "jpg");
$i++;
}
$powerpnt->quit();
?>
below is the error from catch
Error : [13-Apr-2016 23:43:30 America/Los_Angeles] PHP Fatal error: Uncaught exception 'com_exception' with message 'Source: Unknown
Description: Unknown' in C:\inetpub\wwwroot\ppttoimage.php:5
Stack trace:
0 C:\inetpub\wwwroot\ppttoimage.php(5): variant->Open('C:\inetpub\wwwr...')
1 {main}
thrown in C:\inetpub\wwwroot\ppttoimage.php on line 5
I tried giving permissions from command "dcomcnfg" for DCOM extensions and no luck still getting the same error.
Can anyone plz help me with some solution. Thanks in advance.

Related

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(public/user_/,public/user_/)

I am getting this error while using the RecursiveDirectoryIterator.
Fatal error: Uncaught exception 'UnexpectedValueException' with
message
'RecursiveDirectoryIterator::__construct(public/user_/,public/user_/):
The system cannot find the path specified. (code: 3)' in
D:\xam\htdocs\s\upload.php:101 Stack trace: #0
D:\xam\htdocs\s\upload.php(101):
RecursiveDirectoryIterator->__construct('public/user_/') #1
D:\xam\htdocs\s\upload.php(138): dirSize('public/user_/') #2 {main}
thrown in D:\xam\htdocs\s\upload.php on line 101
Here is the code i am using.
function dirSize($directory) {
$size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
$size+=$file->getSize();
}
return $size;
}
Please help!!!
There is a limited context here to see what is going wrong. However it would appear that your giving a directory to D:\xam\htdocs\s\upload.php that is not valid to start the iteration and find the size.
The try/catch option would stop it from throwing an error and failing
function dirSize($directory) {
$size = 0;
try {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
$size += $file->getSize();
}
} catch(Exception $e) {
echo "Error: " . $e;
echo "On: " . $directory;
}
return $size;
}

Uncaught exception 'com_exception' with message 'Failed to create COM object `PowerPoint.Application': Invalid syntax

When I run this below code on live server. It gives me error:
$ppApp = new COM("PowerPoint.Application");
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"])));
$path = get_template_directory_uri();
$ppName = $path."/upload/".$fileName1;
$FileName = $path."/upload/images";
$ppApp->Presentations->Open(realpath($ppName));
$ppApp->ActivePresentation->SaveAs(realpath($FileName),17); //'*** 17=JPG, 18=PNG, 19=BMP ***'
$ppApp->Quit;
$ppApp = null;
PHP Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `PowerPoint.Application': Invalid syntax
This code work well on local server. But not run on live server.
I have been appreciated to send me any suggestions or solution related to this problem.

php not opening file on mounted filesystem

I have the following bit of code that is giving me problems.
#$fullfilename="/data/extract/".$curpkg."/".$curfilename;
$fullfilename = "/tmp/test.txt";
$readline = 0;
$lictext="";
try {
$file = new SplFileObject($fullfilename);
$readline=$curline-1;
while ($readline <= ($curline -1 + $curlinecount)) {
$file->seek($readline);
$lictext = $lictext . $file->current()."\n<br>";
$readline = $readline + 1;
}
} catch (Exception $e) {
$lictext = "couldn't open it $fullfilename<br> Exception: $e<br>";
}
When I use the currently uncommented $fullfilename variable declaration, it works fine, but when I use the code that is commented out it does not. I get the following error:
couldn't open it /data/extract/test.txt
Exception: exception 'RuntimeException' with message \
'SplFileObject::__construct(/data/extract/test.txt):\
failed to open stream: No such file or directory' in \
/srv/www/htdocs/legal/index.php:70
Stack trace:
#0 /srv/www/htdocs/legal/index.php(70): \
SplFileObject->__construct('/data/extract/test.txt')
The only difference is that the data I want to use is a separate drive mounted at /data.
Permissions for the entire structure are 777: drwxrwxrwx 2 root root 53248 Jan 7 14:31 data.
I am at a loss here, I have the same problem with file_exists() and is_readable(). Can anyone give me some guidance here?

unable to read pdf file using imagick

I'm trying to convert a pdf file to a jpeg. But I cant even get the simplest example to work.
<?php
if (!extension_loaded('imagick'))
die('Imagick is not installed');
else
echo 'Imagick installed<hr>';
$inputFile="test.pdf";
if(file_exists($inputFile)){
echo "$inputFile exists.<br>";
}
else{
die("$inputFile doesnt exist.");
}
$imagick = new Imagick();
$imagick->readImage($inputFile);
$imagick = $imagick->flattenImages();
$imagick->writeFile('test.jpg');
?>
The first test says the file exists but imagaick is not able to read the file.
Fatal error: Uncaught exception 'ImagickException' with message
'unable to open image `test.pdf': No such file or directory #
error/blob.c/OpenBlob/2646' in C:\xampp\htdocs\img\index.php:14 Stack trace: #0
C:\xampp\htdocs\img\index.php(14): Imagick->__construct('test.pdf') #1 {main} thrown in
C:\xampp\htdocs\img\index.php on line 14
What am I doing wrong ?
The problem is in your path to pdf file,
simply use $_SERVER['DOCUMENT_ROOT']
$inputFile = $_SERVER['DOCUMENT_ROOT']."/test.pdf";

Fatal error: Uncaught exception 'com_exception' with message. while converting ppt to jpg

When I run blow code:
/*** PPT to Image conversion ***/
$ppt_file = 'E:\wamp\www\temp/a.pptx';
$app = new COM("PowerPoint.application") or die("Unable to instantiate PowerPoint");
$app->Visible = true;
$app->Presentations->Open($ppt_file);
$app->Presentations[1]->SaveAs("E:/tmp/outdir",18);
$app->Presentations[1]->Close();
$app->Quit();
$app = null;
It gives me one exception :
Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Office PowerPoint 2007Description: PowerPoint could not open the file.' in E:\wamp\www\temp\video_conversion.php:107 Stack trace: #0 E:\wamp\www\temp\video_conversion.php(107): variant->Open('E:\wamp\www\tem...') #1 {main} thrown in E:\wamp\www\temp\video_conversion.php on line 107
I am unable to figure out what is the problem.
This is kind of issue is due to the following factors.
PHP.ini settings
Folder Permission
allow open is not enabled in the server
allowed upload size
Within your error, you see the following message: PowerPoint could not open the file.' in E:\wamp\www\temp\video_conversion.php:107
Does the PHP user have permissions to the file E:\wamp\www\temp/a.pptx?
Try correcting your slashes: E:\wamp\www\temp\a.pptx as / normally refers to an option or argument.
At the end of the day, it appears to be a permissions error, a location issue or alike which is preventing access to that file. Can you open the file with fopen or file_get_contents?
Try this with com class:
COM class Reference: - http://us2.php.net/manual/en/class.com.php
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
$ppApp = new COM("PowerPoint.Application");
$ppApp->Visible = True;
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$ppName = "MySlides.ppt";
$FileName = "MyPP";
//*** Open Document ***//
$ppApp->Presentations->Open(realpath($ppName));
//*** Save Document ***//
$ppApp->ActivePresentation->SaveAs($strPath."/".$FileName,17); //'*** 18=PNG, 19=BMP **'
//$ppApp->ActivePresentation->SaveAs(realpath($FileName),17);
$ppApp->Quit;
$ppApp = null;
?>
PowerPoint Created to Folder <b><?=$FileName?></b>
</body>
</html>
Or try this :
$powerpnt = new COM("powerpoint.application") or die("Unable to instantiate Powerpoint");
$presentation = $powerpnt->Presentations->Open(realpath($file), false, false, false) or die("Unable to open presentation");
foreach($presentation->Slides as $slide)
{
$slideName = "Slide_" . $slide->SlideNumber;
$exportFolder = realpath($uploadsFolder);
$slide->Export($exportFolder."\\".$slideName.".jpg", "jpg", "600", "400");
}
$powerpnt->quit();

Categories