I've been trying to figure this out for the life of me: I asked the question on stackoverflow, but they weren't able to help: http://stackoverflow.com/questions/42967583/executing-a-linux-program-from-php <?php $file = 'C:\xampp\htdocs\SMF\sdsdssss.docx'; $content = exec( 'C:\xampp\htdocs\SMF\doctotext\doctotext.exe /c '. $file , $output ); var_dump( $output ); Code (markup): How do I write this code on a linux server (Centos x86_64)? I'm using this free software: http://silvercoders.com/en/products/doctotext/ The first person to get an answer will get $20 USD to their PayPal. I tried: $file = '/home/***/public_html/downloads/test_doc.docx'; $content = exec('/home/***/public_html/doctotext/doctotext.sh \c '. $file, $output, $return); Code (markup):
And, what exactly does that return, in the php-error-log, other error-logs, or anything at all? Besides, I'm guessing using -c or --c instead of \c might help? As long as the exec() works on your server, running a .sh shouldn't be any different, although the syntax and output might be slightly different.
Hi No PHP errors, unfortunately. var_dump( $content ): string(0) "" var_dump( $output ): array(0) { } var_dump( $return ): int(126) var_dump( $string ): string(0) "" Code (markup): If I give you FTP access, could you try it? I've asked everyone, and no help
Have you tried running the file manually, from the command-line (SSH) to see if it works as intended there?
How am I supposed to know? I don't know the program, or the syntax - I'm generalising here. Read the documentation, or the man page, or try running the program with a -help modifier or similar. If you use a non-existing modifier, it will normally list the available modifiers.
I understand but I linked the software and its free to download. I was hoping someone could try it on their server.
I think you are trying to read a docx file into a text string. This code below works. It doesn't use the software you are using... Here's the output: http://www.imrobos.com/dd/1.php Here's the docx file: http://www.imrobos.com/dd/aa.docx Any reason you want to use the third party software? <?php function docx2text($filename) { return readZippedXML($filename, "word/document.xml"); } function readZippedXML($archiveFile, $dataFile) { // Create new ZIP archive $zip = new ZipArchive; // Open received archive file if (true === $zip->open($archiveFile)) { // If done, search for the data file in the archive if (($index = $zip->locateName($dataFile)) !== false) { // If found, read it to the string $data = $zip->getFromIndex($index); // Close archive file $zip->close(); // Load XML from a string // Skip errors and warnings $xml = new DOMDocument(); $xml->loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING); // Return data without XML formatting tags return strip_tags($xml->saveXML()); } $zip->close(); } // In case of failure return empty string return ""; } echo docx2text( "aa.docx"); // Save this contents to file ?> PHP:
Reason is because I need a full solution for all document types, not just docx. I found this package on GitHub (doctotext). I'd like to install it on my Centos-running dedicated server (x86_64), but I do not know how. Could someone offer instructions as to how I could do it. There are no instructions provided, unfortunately
Did you check your phpinfo file? Generally commands like exec, passthrough etc are in the "disabled_functions" list.
Hi, I downloaded the package you linked, and it has a "makefile" inside the "src" directory. You need to install the doctotext using this first. Unzip the package, go to src directory, and run commands: configure make make install I've never installed a package on linux myself, but found this link that might help: http://www.linuxquestions.org/questions/linux-newbie-8/help-how-to-install-a-makefile-872181/ You can hire someone to do this for you, but make sure its a genuine, trustworthy person since you will give him root access... Why don't you contact your webhost? May be they will install this for a fee? Once done, they can just use commandline to check if its extracting text from one of the sample files that are in the downloaded zip. From there on you can figure out the PHP code easily...
I'm the owner of the dedicated server, so there isn't a host, unfortunately. Still waiting for someone to try it out before I do. Thank you for your assistance though
I don't think you can run a .EXE file directly on linux. You'll need some other third party binary anyways. https://www.techperiod.com/install-windows-exe-files-linux/ I think that is the problem. The EXE is not getting executed. This is why I asked you to install the doctotext binary first, and then try your existing code. Instead of location to .exe file, give location to this doctotext binary in the exec command. You can hire someone from here, or from stack, or from freelancer who can do the install and run a test from commandline
Hi, not sure if this will help, but Windows and Linux use different line endings in their files which can cause issues with code being executed on a different environment. Windows uses CRLF while Linux uses LF, check in your editor for settings to save your files as LF. I use Atom Editor for coding, it has an option to automatically save to a set format, i code everything with LF as it works on both systems without issue. Also double check the file paths in the code and that your server stack is properly set in the Linux environment paths. Sidenote I'm a noobie, but faced these issues before on a Linux server, those changes helped me.
Jeet's "I don't think you can run a .EXE file directly on linux." has only one error - it's not "I don't think", it's "you can't". You'll have to find a Linux program that does what doctotext.exe does, or just write the function of that program inside your PHP program (in PHP, of course). PHP can read an xml file, so it's pretty trivial. (I know exactly how trivial it is - I've written it. Unfortunately, every time I did, it was proprietary, so I can't give you the code, but simplexml_load_string($XMLData) should be easy enough to figure out.)
They have a new version out for both windows and linux, I am using it on windows but there is documentation in both so you should be fine: https://sourceforge.net/projects/doctotext/