SMFHacks.com

Modifications/Themes => General SMF Forum => Topic started by: shuban on March 21, 2017, 05:49:30 pm

Title: Extreme coding help
Post by: shuban on March 21, 2017, 05:49:30 pm
I'm trying to execute a program that converts documents into plain text.

http://silvercoders.com/en/products/doctotext/

I've tried contacting the developer, but offers no help. My test server is on my Windows PC:

I would like to run the program in PHP. Here's what I have so far

Code: [Select]
<?php

$location 
'C:\\xampp\\htdocs\\test_doc.docx';

$output exec("C:\\doctotext\\doctotext.exe /c $location");

echo 
'The output: '.$output;

?>

Could someone steer me in the right direction? There are absolutely no examples on the internet using this free, powerful program.
Title: Re: Extreme coding help
Post by: SMFHacks on March 21, 2017, 07:57:29 pm
You have to make sure the webserver has permission to execute the program doctotext.exe
You should give Apache access to that whole folder.

I would do this as well
$location = '"C:\\xampp\\htdocs\\test_doc.docx"';
Title: Re: Extreme coding help
Post by: shuban on March 21, 2017, 11:18:05 pm
I'm using XAMPP. Not sure how to do what you recommended. I wish I could get someone to try this out on their server, really stuck.
Title: Re: Extreme coding help
Post by: shuban on March 22, 2017, 12:41:46 pm
Good news, I got it working on my Windows based server:

Code: [Select]
<?php 

$file 
'C:\xampp\htdocs\SMF\sdsdssss.docx';

$content exec'C:\xampp\htdocs\SMF\doctotext\doctotext.exe /c '$file $output );

echo 
'output of the file after read by doctotex.exe: ' ;
echo 
nl2br("\n");
print_r$output );

echo 
nl2br("\n");

$string '';

foreach ( 
$output as $o ) {
    
$string .= $o;
}

echo 
nl2br("\n");

However, how would I get this to work on my Centos server? Obviously I'd have to download the Linux version of the software, but how do the codes change?
Title: Re: Extreme coding help
Post by: SMFHacks on March 22, 2017, 12:49:29 pm
It would be a different path to binary file.
Title: Re: Extreme coding help
Post by: shuban on March 22, 2017, 12:55:44 pm
Please advice, I placed doctotext into:

Code: [Select]
/home/***/public_html/doctotext
and the file:

Code: [Select]
/home/***/public_html/downloads/test_doc.docx
Title: Re: Extreme coding help
Post by: SMFHacks on March 22, 2017, 12:57:47 pm
That would do it.
You would need to check the file permissions on doctext maybe try giving it 777
Title: Re: Extreme coding help
Post by: shuban on March 22, 2017, 01:01:43 pm
That would do it.
You would need to check the file permissions on doctext maybe try giving it 777

On the folder or the file itself? Should I do it recursively so that everything inside gets 777?

Code: [Select]
$file = '/home/***/public_html/downloads/test_doc.docx';

$content = exec( '/home/***/public_html/doctotext/doctotext \c '. $file , $output );

This didn't work...
Title: Re: Extreme coding help
Post by: SMFHacks on March 22, 2017, 01:14:39 pm
Make sure it is part of the same user group as apache/webserver
Also make sure the file has excute permissions.

The program for sure. Maybe the whole directory if it is saving information to that folder.
Title: Re: Extreme coding help
Post by: shuban on March 22, 2017, 01:25:11 pm
The owner and group is both root.

I tried making everything 777, didn't help.

How would I check logs for this? Do logs even exist?
Title: Re: Extreme coding help
Post by: SMFHacks on March 22, 2017, 01:31:43 pm
You could see if $content contains anything that is returned.
Title: Re: Extreme coding help
Post by: shuban on March 22, 2017, 05:27:54 pm
I checked and it doesn't return anything unforunately
Title: Re: Extreme coding help
Post by: shuban on March 22, 2017, 11:42:44 pm
The command is wrong. The fact I'm using /c means it's incorrect.
Title: Re: Extreme coding help
Post by: shuban on March 23, 2017, 02:11:33 pm
Do you have any other suggestions?

I asked this on Stack overflow, and got this response: http://stackoverflow.com/questions/42967583/executing-a-linux-program-from-php/42970170?noredirect=1#comment73058411_42970170

I think I'm running out of ideas
Title: Re: Extreme coding help
Post by: SMFHacks on March 23, 2017, 08:37:58 pm
Not really stackoverflow is a good place though those people who reply to questions are experts.