So I am using the call php_com_dotnet in my code:
$word = new COM("word.application");
// Hide MS Word application window
$word->Visible = 0;
//Create new document
$word->Documents->Add();
// Define page margins
$word->Selection->PageSetup->LeftMargin = '2';
$word->Selection->PageSetup->RightMargin = '2';
// Define font settings
$word->Selection->Font->Name = 'Arial';
$word->Selection->Font->Size = 10;
// Add text
$word->Selection->TypeText("TEXT!");
// Save document
$filename = tempnam(sys_get_temp_dir(), "word");
$word->Documents[1]->SaveAs($filename);
// Close and quit
$word->quit();
unset($word);
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");
// Send file to browser
readfile($filename);
unlink($filename);
and I got his error:
Fatal error: Uncaught Error: Class 'COM' not found in /var/www/clients/client1/web1/web/nordin/save.php:6 Stack trace: #0 {main} thrown in /var/www/clients/client1/web1/web/nordin/save.php on line 6
so I looked around I added this to my php.ini file:
[COM_DOT_NET]
;extension=php_com_dotnet.dll
enable_dl = On
; extension_dir = "ext"
and it still doesn't work, what am I doing wrong? please help!
EDIT
my files are on a sftp server and I get error's like this:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
The semi-colon before the extension is a comment and means that extension is not enabled. To enable it you must remove that semi-colon:
;extension=php_com_dotnet.dll
becomes
extension=php_com_dotnet.dll
You may need to restart IIS after making this change.
Related
I am at an internship right now and got this old 2012 code, I have tried my best to debug it but I can only get this error. I have already tried to increase my PHP limit in php.ini and that did nothing. it also isn't the XML file because I can print the entire thing to the website with no problem. it might be a problem with the file locking since this is the first time I have used it.
this is the PHP
<?PHP
// First Clear any status messages from CMS
// Find filepath
$dir = getcwd();
$pieces = explode("/", $dir);
$processname = $pieces[count($pieces) - 1];
$recmsgfilepath = "savedmsg.default.xml";
//saved for later use in $recmsgfilepath
//tmp/webpage/".$processname."/msgfromcms.xml
// Lock file
$newmsgfile = fopen($recmsgfilepath, "r+");
while(!flock($newmsgfile, LOCK_EX))
{
// Continue to try to lock file, webserver will eventually terminate PHP script
}
$newmsgdoc = new domDocument();
if((filesize($recmsgfilepath) > 0) && $newmsgdoc->load($recmsgfilepath))
{
// Clear rec message file
ftruncate($newmsgfile, 0);
}
flock($newmsgfile, LOCK_UN); // release the lock
fclose($newmsgfile);
// Check if any buttons pressed
if(isset($_POST['clearmessages']))
{
// Send message to delete all messages in web app
SendMessage("", "WEBVIEW", "4", "", "", "", "", "");
}
the xml
<SAVEDMESSAGES last_changed="16449122918046">
<TEXTMESSAGE TIMESTAMP="16449122918046" TIMESTAMP_MSG="1644912290" PRIO="0" ALARMID="-">
<TIME>09:04:50</TIME>
<DATE>2022-02-15</DATE>
<ADDRESS></ADDRESS>
<PRIO>0</PRIO>
<TIMEOUT>60</TIMEOUT>
<TEXT>TESTMESSAGE</TEXT>
<ALERTTYPE>0</ALERTTYPE>
<CALLBACK></CALLBACK>
<SENDERID></SENDERID>
<ALARMINITIATOR>0</ALARMINITIATOR>
<ACKDATA></ACKDATA>
<POSINFO1>0</POSINFO1>
<POSINFO2>0</POSINFO2>
<RFP0>0</RFP0>
<STATUS>ORIGINAL</STATUS>
<ORIGIN>CONFIG</ORIGIN>
<MESSAGEID>338599</MESSAGEID>
</TEXTMESSAGE>
</SAVEDMESSAGES>
While running the code which is used to connect to the workbook I get fatal error.
Here's the code:
<?php
$filename = "C:/Users/.../Output.xlsb";
$sheet1 = "DAILY_OUTPUT";
$sheet2 = "DAILY_OUTPUT";
$excel_app = new COM("Excel.application") or Die ("Did not connect");
$Workbook = $excel_app->Workbooks->Open("$filename") or Die("Did not open $filename $Workbook");
$Worksheet = $Workbook->Worksheets($sheet1);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_result\n";
$Worksheet = $Workbook->Worksheets($sheet2);
$Worksheet->activate;
$excel_cell = $Worksheet->Range("C4");
$excel_cell->activate;
$excel_result = $excel_cell->value;
print "$excel_result\n";
#To close all instances of excel:
$Workbook->Close;
unset($Worksheet);
unset($Workbook);
$excel_app->Workbooks->Close();
$excel_app->Quit();
unset($excel_app);
And when I run it from PhpStorm to Google Chrome it shows:
Fatal error: in C:\Users\...\excCon.php on line 6
Edit: the "..." are just to shorten the URL here
Solution was wrong slashes.
Instead of single / I put double \ and now the path to the file is correctly read.
I have been trying to compile latex from php. I got the help from this tutorial. However, I keep getting this error.
Error: Invalid XRef stream header Error: Invalid XRef stream header pdf.worker.js:232:5
XRef_readXRef#resource://pdf.js/build/pdf.worker.js:3708:13
XRef_parse#resource://pdf.js/build/pdf.worker.js:3296:23
PDFDocument_setup#resource://pdf.js/build/pdf.worker.js:2469:7
PDFDocument_parse#resource://pdf.js/build/pdf.worker.js:2350:7
ensureHelper#resource://pdf.js/build/pdf.worker.js:1971:22
NetworkPdfManager_ensure/<#resource://pdf.js/build/pdf.worker.js:1985:7
NetworkPdfManager_ensure#resource://pdf.js/build/pdf.worker.js:1965:1
BasePdfManager_ensureDoc#resource://pdf.js/build/pdf.worker.js:1832:14
loadDocument/
Note: I have installed texlive in ubuntu so I can use pdftex.
xelatex is also installed.
Web server content:
small latex file contained "latex_template.php" and the
index.php contains the following php script.
ob_start();
include 'latex_template.php';
$outputData .=ob_get_contents();
ob_end_clean();
$texFile = tempnam(sys_get_temp_dir(), 'test');
$base = basename($texFile);
rename($texFile, $texFile.".tex");
$texFile .= ".tex";
file_put_contents($texFile, $outputData);
chdir(dirname(realpath($texFile)));
$console = shell_exec("xelatex {$base}" );
//$console = system("xelatex {$base}" );
header('Content-Type: application/pdf');
$pdf = dirname(realpath($console)).DIRECTORY_SEPARATOR.$base.".pdf";
readfile($pdf);
Note: Manual execution xelatex: log file:
I've created a PHP project that converts JSON format into AVRO format.
The original project requires PHP libs that I'm not sure how to add on EMR.
This is the stderr log received by EMR:
PHP Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in /mnt/var/lib/hadoop/tmp/nm-local-dir/usercache/hadoop/filecache/12/convert-json-to-avro.php on line 3
PHP Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /mnt/var/lib/hadoop/tmp/nm-local- dir/usercache/hadoop/filecache/12/convert-json-to-avro.php on line 3
log4j:WARN No appenders could be found for logger (amazon.emr.metrics.MetricsUtil).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
And here is the main code for the mapper:
#!/usr/bin/php
<?php
require_once 'vendor/autoload.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
$outputFile = __DIR__ . '/test_avro_out.avr';
$avroJsonSchema = file_get_contents(__DIR__ . '/HttpRequestEvent.avsc');
// Open $file_name for writing, using the given writer's schema
$avroWriter = AvroDataIO::open_file($outputFile, 'w', $avroJsonSchema);
$counter = 1;
while (($buf = fgets(STDIN)) !== false) {
try {
//replace ,null: with ,"null": to prevent map keys which are not strings.
$original = array("null:","userIp");
$replaceWith = array("\"null\":", "userIP");
$data = json_decode(str_replace($original, $replaceWith, $buf), true);
//print_r($buf);
if ($data === false || $data == null ) {
throw new InvalidArgumentException("Unable to parse JSON line");
}
$mapped = map_request_event($data);
var_dump($mapped);
//$avroWriter->append($mapped);
//echo json_encode($mapped), "\n";
} catch (Exception $ex) {
fprintf(STDERR, "Caught exception: %s\n", $ex->getMessage());
fprintf(STDERR, "Line num: %s\n",$counter);
fprintf(STDERR, "buf: %s\n", $buf);
}
$counter++;
}
$avroWriter->close();
Notice I'm using the require_once 'vendor/autoload.php'; which states that autoload.php is under the folder vendor.
What is the right way to load the vendor folder into the EMR cluster (there are needed files there)?
Should the require_once path change?
Thanks.
Following Guy's comment I've used a bash script similar to the one you can find here.
I've changed the require_once 'vendor/autoload.php' line in the code to point to the location where i dropped my files. (/home/hadoop/contents worked perfect).
lastly I've added an EMR bootstrap custom step where you can add the bash script so it can run before the PHP streaming step.
I am trying to load a file to my Cloud Files Container from a remote file.
Below is the example code a Cloud Files Support person gave me:
<?php
require('cloud/cloudfiles.php');
$res = fopen("http://images.piccsy.com/cache/images/66653-d71e1b-320-469.jpg", "rb");
$temp = tmpfile();
$size = 0.0;
while (!feof($res))
{
$bytes = fread($res, 1024);
fwrite($temp, $bytes);
$size += (float) strlen($bytes);
}
fclose($res);
fseek($temp, 0);
//
$auth = new CF_Authentication('user','token ');
//Calling the Authenticate method returns a valid storage token and allows you to connect to the CloudFiles Platform.
$auth->authenticate();
$conn = new CF_Connection($auth);
$container = $conn->create_container("example");
$object = $container->create_object("example.jpg");
$object->content_type = "image/jpeg";
$object->write($temp, $size);
fclose($temp);
?>
The problem I am getting is the below error:
Fatal error: Call to a member function create_container() on a non-object in /home2/sharingi/public_html/daily_dose/remote_test.php on line 24
Not sure exactly what I am not noticing here.
It seems $conn did not successfully instantiate an object. That is the problem, but the solution is not clear cut.
Is CF_Connection defined? Does error_reporting(E_ALL) give you more helpful info? What does var_dump($conn instanceof CF_Connection) output?
This should point you in the right direction.