I have a server whch runs a little app that we use to create .docx.
It worked perfectly on an old server but I had to move it on another one and now it has a great problem: when I run my php script - based on PHPWord - the output files are broken and cannot be used (MS Word reports "The file xyz.docx cannot be opened because there are problems with the contents).
Also changing the file extension from .docx to .zip (just to take a look to its content) doesn't help.
The "funny" side of this problem is that on the same server, using the same version of PHP, with nginx 1.2.3 it disappears and the .docx file are perfect (ok, if don't care of the content... but this is another problem...).
I could switch on nginx but I have a different issue on it: I can't read Latin1 special chars as expected.
After having googled and searched into the code for a long while, I found that the problem is with the following line, contained in the Template.php library of PHPWord, lin 105:
$this->_objZip->addFromString('word/document.xml', $this->_documentXML);
It apparently works fine (and on nginx it really works fine) but it produces a fake .docx, impossible to open.
I tried different versions of the apache server with no luck, so I would really appreciate any help.
Summarizing:
I tested my script (which uses PHPWord) on a Windows Server 2003 host and php 5.2.8
It works fine with nginx
It produces a bad .docx file with apache (ZipArchive addFromString doesn't work)
I tested it using several Apache versions, from 2.0.64 up to 2.2.25
I can't see any error message
Any idea?
You can use PclZip instead of ZipArchive.
The sample code :
\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
Related
I've installed LAMP on my Ubuntu laptop with no apparent problems and successfully did the phpinfo() test by navigating to the file through the browser. But the same file is downloaded instead of executing when I'm trying to build from Sublime Text 3 using the following script:
{ "cmd": ["/opt/google/chrome/google-chrome" ,"$file"] }
That worked the first couple of times I tested it, but stopped right after I changed the name of the build system and hasn't been functioning since even after I reversed the change. How would I go about fixing the issue?
$file is "The full path to the current file, e.g., C:\Files\Chapter1.txt.".
Apache isn't causing the file to be downloaded; you aren't requesting it from Apache.
You need to translate $file into a URL on your HTTP server.
So I am following TheNewBostons video guide:
https://www.youtube.com/watch?v=vQCIZOv1su0&list=PL6gx4Cwl9DGDdCg0Jli_WTZd5JIliDY62&index=3
(On how to manually install Apache, php and MySQL)
Getting to the 3rd video where I am about to make the "Tuna baby!" php file to test it out I get the error "404 Not Found". I don't have Notepad++ so I am just using Notepad and naming it .php at the end. If I only write localhost is says "It works!", so Apache is working.
Not Found
The requested URL /tuna.php was not found on this server.
The weird thing is that I had no problems while doing this on my main computer but now I am doing it on my laptop and seem to have the problem every time I try doing it. Had to uninstall everything with "Revo Uninstaller" to remove all the traces and so on so this should be a clean install.
Any idea why it is not working?
Installed Notepad++, saved the file properly as a php file and it worked.
Ive created a test page to test using Prince xml but this code doesn't seem to work.
index.php
require_once("prince.php");
$prince = new Prince('www1.must.edu.ph/tts/prince/Engine/bin/prince.exe');
$prince->setHTML(true);
$html = file_get_contents("reportHeader.html");
$ret = $prince->convert_string_to_file($html,'www1.must.edu.ph/tts/prince/Engine/bin/pink.pdf');
echo $html;
if($ret)
echo "converted";
else
echo "not";
whenever I access the page, there is no error.. it just displays the echoed $html and 'not'..
Problem 1:
I spotted the problem. You run PHP code in an .html ? Change the file extension to .php and re-upload to PHP-enabled hosting server & retry.
Problem 2:
The constructor does not set correctly. The constructor requires an absolute path on server, instead of an URL. The readme.html already mentioned this. It should look like:
$prince = new Prince('/usr/local/bin/prince');
In read me, it said:
On Windows, be sure to specify the path to the prince.exe file located
within the Engine\bin subfolder of the Prince installation.
Note: Most of the PHP-enabled hosting server are NOT Windows-based; even it's Windows-based, it won't allow you to execute .exe .
This happened to me, so I used SSH to access my server and realized that I did not have a font library installed. If you are using something like CentOS, then you will need to install a font library first. I found this helpful http://blog.whatgeek.com.pt/2011/11/10/install-core-fonts-centos-6/
Running Prince on a virtual box on my Mac using the YesLogic PHP wrapper and parsing the PHP files with a web browser. No PDF output, no errors reported by the wrapper.
The answers above didn't resolve the issue for me.
So I parsed the PHP files from the command line using 'php -f index.php' and it worked. Stupid mistake on my part - my PHP files simply didn't have the correct permissions.
I have Joomla installed in my computer, but recently have been writing php files that aren't related to the Joomla-managed site. For some reason, when I try to open those php files in the web browser using xampp (note: Joomla also is using xampp), the browser doesn't process the code w/in the tags as php code.
For example, after opening a basic page (a page with title "test", no content except in the body tags) in the web browser and going to the source code, the following is shows up in the source code:
<body>
<?php echo "hello"; ?>
</body>
instead of the HTML conversion. (i.e. just "hello")
Does anyone have an idea about what's going on here?
Thanks.
It's probably because PHP module isn't loaded in your apache. Be sure it is enabled
PHP is interpreted in the server, not the browser. Whatever's going wrong, you need to look at the SERVER side to resolve it.
My first guess: maybe you didn't suffix the file ".php" (so the server doesn't recognize it as a PHP file?)
Second guess: is the directory containing your PHP files configured to parse PHP?
If you have Joomla, you probably have PHP. You probably also have Apache.
So check your Apache configuration, and check your file naming conventions.
Is the file extension .php? The server doesn't magically know when you're serving php files, this is a good way to ensure it knows what you're doing.
Apache is looking into your localhost's defined root directory for files it can parse. In this case htdocs. This is the default for XAMPP. As far as Apache is concerned, it will not interpret any files outside of that folder.
if the problem in php module it better to re install php5 in to the system and it will work fine. probably the problem is in php module you should try re installing php in your system.
Just restart httpd service. It will work fine.
sudo systemctl restart httpd.service
if it has not worked please reinstall PHP once again.
I have a quick question that I can't figure out. I've tried searching Google and following examples, but I can't find anything.
I have an HTML form that I'm trying to process with a PHP file, but when I submit the form, it merely prints the source of the PHP file, it doesn't execute it. If I run the PHP file by itself (not indirectly through the HTML button), it works fine.
HTML form header:
<form id="registrationform" name="registrationform" method="post" action="processregistration.php">
Submit button:
<button type="submit" value="Submit" >Create</button>
The PHP form is just <?php print "Hello"; /?
Again, it runs fine if I just run the PHP file, but prints the PHP file (doesn't run) when it gets called through the HTML form.
Any help is appreciated.
edit-Running locally through Coda
edit-Here is the output that I'm getting:
Output when the PHP is called through an HTML action:
</php
print "Hello";
?>
Output when I run the PHP directly through Coda:
Hello
I had the same problem and just fixed it on my coda version 1.7.4
I installed MAMP on my mac and set up the apache path under MAMP preferences to the folder where my sites are located;
/Users/yourUserName/Sites
this points MAMP's 'http://localhost:8888' address to your sites folder, if you paste that on your browser you'll now see your sites folder's content in the browser.
then, all you do is point the local site's connection settings to the site you are testing;
I was going to post an image, but I'm new to the site and wasn't allowed.
Under my site's preferences i set up the addresses as follows;
Root URL : 'http://localhost:8888/yourSiteRootFolder/'
Local URL : 'http://localhost:8888/yourSiteRootFolder/'
Remote Root : /yourSiteRootFolder/
Local Root : /Users/amartinez/Sites/yourSiteRootFolder/
I hope this is related to the problem you're having and helps you fix it.
Line #19 from Coda 1.6 Release notes:
Coda no longer tries to locally
preview a remote PHP file while
editing/previewing
Listed under "Improvement" - doubt they brought it back for the 1.7 release.
I'm running Apache2/PHP5 10.5.8 OS X (no problem reproducing your issue with Coda)
Even when running my form.html and post.php files from /Library/WebServer/Documents folder.
My sample files work fine in the Apache env....I just needed to run them through Coda to "break" them. :-)
Are you sure the html file and the php script are on a server with php support enabled?
I've never used Coda, but you need to be running it through a server (e.g. Apache + PHP). You cannot just open the file itself within Windows.
Try looking at xampp as a quick server for testing.
If it works properly, you should be viewing the PHP file on something like http://localhost/test.php instead of file:///something/test.php.
This may be because you don't have PHP installed on your server. I would check to make sure that your hosting package included PHP, pre installed.
Here are some resources to get you started with that, if not installed:
http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
http://www.php.net/manual/en/install.php
http://www.w3schools.com/PHP/php_install.asp
Edit: actually, I think I may have found it.
If you look at the starting PHP tag, you have a slash instead of a ?. If that's in your script, just change that to <?php. But it may not be, it could be that's just question format-ing.