Crystal Report by using CRExport via PHP - php

I'm trying to generate a crystal report via a php script.
I was able to successfully use crexport to generate a pdf report. However when I try to execute the script via php's exec command I get this error.
c:\inetpub\wwwroot\mamobile\crexport -F c:\inetpub\wwwroot\mamobile\reports\customer.rpt -O c:\inetpub\wwwroot\mamobile\output\test.pdf -E pdf -S testdb
Crystal Reports Exporter Command Line Utility. Version 2.1.11.1103
Copyright(c) 2011 Rainforest Software Solution http://www.rainforestnet.com
Misc Error: Load report failed.
Type "crexport -?" for help
It works fine via the command prompt.

This is unlikely but is your report by any chance still open in the Crystal Designer when you were running this script? I was getting this error when the .rpt file was open.

it works.
remember to not be with the open rpt file in graphics editor
$output = '';
$command = 'c:\inetpub\wwwroot\mamobile\crexport -F c:\inetpub\wwwroot\mamobile\reports\customer.rpt -O c:\inetpub\wwwroot\mamobile\output\test.pdf -E pdf -S testdb';
exec($command, $output);
var_dump($output);

Related

Run gradle from PHP file

I am trying to compile an android app from a PHP file:
<?php
$command = "sh build.sh";
$output = shell_exec($command);
print $output;
?>
My file build.sh:
#!/bin/bash
export JAVA_HOME=/var/www/vhosts/mydomain.com/android-sdk/jdk1.8.0_73/
export PATH=${PATH}:${JAVA_HOME}/bin
export GRADLE_HOME=/var/www/vhosts/mydomain.com/android-sdk/gradle-2.11/
export PATH=${PATH}:${GRADLE_HOME}/bin
export GRADLE_USER_HOME=/var/www/vhosts/mydomain.com/workspace/gradle_user_home/
gradle --info --debug build 2>&1
When I open the PHP file in the browser, I get this error:
* What went wrong: 00:45:56.317 [ERROR] [org.gradle.BuildExceptionReporter] Failed to load native library 'libnative-platform.so' for Linux amd64.
If instead of Shell_exec I use exec() it shows just this:
[ERROR] [org.gradle.BuildExceptionReporter]
If I run gradle from the command line, everything works fine, I think the issue must be with the user, with shell_exec() the gradle command is exectuted with apache user, but I can not find a solution.
Thanks!

Not able to run wkhtmltopdf commad through shell_exec() function in php but same command works on command line

I'm in trouble and that much confused about a php shell_exec command.
When the command is execute by PHP I have no error but the execution fails. If I use exactly the same command from a terminal it works.
Here's the command :
/usr/bin/wkhtmltopdf --lowquality --dpi 300 --encoding utf-8 "/tmp/knplabs_snappyxa9otq.html" "/tmp/knplabs_snappyv3pD7h.pdf"
When I lauch this from a terminal :
$ /usr/bin/wkhtmltopdf --lowquality --dpi 300 --encoding utf-8 "/tmp/knplabs_snappyWG9XTd.html" "/tmp/knplabs_snappyv3pD7h.pdf"
Loading page (1/2)
Printing pages (2/2)
Done
But from my php script :
// Construct the previous command
$command = $this->buildCommand($url, $path);
../..
shell_exec($command);
../..
$content = file_get_contents($path);
../..
I've test the output of shell_exec, it's empty.
The log :
Warning: file_get_contents(/tmp/knplabs_snappyv3pD7h.pdf): failed to open stream: No such file or directory in /*****/lib/snappy/SnappyMedia.class.php on line 64
No permission pb in the /tmp directory :
$ ls -la /tmp
total 448
drwxrwxrwt 16 root root 4096 mars 12 21:51 .
../..
I've tried avec the PHP exec() function to get error informations, I just get an "1" error code in return_var and nothing in output.
For information this issue appear on my test server, my desktop computer but not on my notebook. All the 3 are with sames PHP, Apache, Mysql versions.
I don't understand anything ...
Thanks for any help, I'm loosing my mind.
David.
I've found the solution here : Executing wkhtmltopdf from PHP fails
Thanks to Krzychu.
First to get information from the shell_exec command add " 2>&1" at the end of the command. In that way you will get information in return of the command :
$no_output = shell_exec($command);
echo $no_output; // nothing
$output = shell_exec($command . ' 2>&1');
echo $output; // in my case : "cannot connect to X server"
The solution :
Not use the wkhtmltopdf ubuntu package (0.9.9-4)
Use the official package from the Wkhtmltopdf download page
So no need to install xvfb ! (I've seen this advice many times)
Looks like a user's permissions issue.
When you run the command from the terminal, it is the user account, currently used, which does have the right permissions, to run a command in /usr/bin, and execute the specific file.
When you run it from the php script, it is the http server account on your system, which needs the permission to execute the file in /usr/bin. Usually this is the apache user.
How you should setup permissions depends on your system. Just remember that what is allowed for apache, is allowed for anyone accessing your http server.
I have had this problem for ages and adding . ' 2>&1' after the $command has somehow solved the problem.
this:
$output = shell_exec($command . ' 2>&1');
instead of:
$output = shell_exec($command);
No idea why but it works and I'm grateful.
Is it a shared hosting? It seems like shell_exec is a restricted function. Try running error_reporting(E_ALL); ini_set('display_errors', 1); before calling shell_exec.
I stumbled upon the same Problem, in my case an absolut Path in the exec Command like /var/www did not work, I had to use relative Paths from the point where I executed the php File.
I also wanted to notice, that it did not work using shell_exec, however it worked using normal exec command, not sure wheres the difference here.

FFMPEG command doesn't work in PHP. (Incompatibilty with MAMP)

I'm a bit of a beginner when it comes to PHP, and I'm trying to create a simple(ish) system where files are input, and then converted to html5 video in various resolutions.
I've sorted out how to handle multiple file uploads etc, but now I'm having a problem.
I can't seem to get exec to execute FFMPEG in PHP.
For example, if I type this into my command line (Terminal on Mac OSX 10.8), It converts the video correctly:
ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov
This correctly outputs the converted video file into my home directory.
However if I run this in PHP as follows:
exec('ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov');
Absolutely nothing happens ... my stat monitor doesn't register any change in processor use, and I can't find the output file anywhere on my system.
Since I'm a bit of a noob at this, I'm assuming I'm doing something wrong, but what is it?
Thanks,
Charlie
After alot of help from birgire and a lot of fiddling around I've sorted it.
This problem comes from an incompatibility with the MAMP sandbox. Which can be solved as follows:
Go to Terminal and type:
sudo nano /Applications/MAMP/Library/bin/envvars
Then comment out the following lines with a hash (#)
# DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
# export DYLD_LIBRARY_PATH
And then add the following line to the file
export PATH="$PATH:/opt/local/bin"
Then, go back to MAMP and restart your servers, navigate back to the page, and you'll be good to go.
You should first try to see if exec() is allowed:
<?php echo exec('echo "exec() is working"');?>
if it's working you should get
exec() is working
If it works you should try
exec('/full/path/to/ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov');
I had the same problem, If you use MAMP, the problem is because mamp's php can't find the correct library, I don't know why!, so.. here's the trick.
- You should use system's php to execute the php which will call to ffmpeg
In your php code (ex: lib.php | index.php):
function callToSysPHP ($videoName) {
// $cmd = '/path to php/php <your php script> args';
// In my case
$cmd = '/usr/bin/php myffmpeg.php ' . $videoName;
shell_exec($cmd);
}
In myffmpeg.php:
$videoName = $argv[1];
//$cmd = 'path to your ffmpeg/your ffmpeg command';
// In my case my ffmpeg cmd looks like
$cmd = '/usr/sbin/' . 'ffmpeg -f image2 -framerate 25 -i ./files/pngs/%1d.png -vf scale=480:640 -vcodec libx264 -refs 16 -preset ultrafast ./files/pngs/'. $videoName .'.mp4 2>&1';
echo '<pre>'; print_r(shell_exec($cmd)); echo '</pre>';
Basically from your mamp php, call a system php to execute a php file wich calls a ffmpeg throught shell_exec();
I hope this can help you.
have you ffmpeg installed on windows machine? what happens if you run the same command from command line without php, does it work? If it doesn't, it hasn't to do anything with PHP.
If '/usr/local/bin/' is the directory where you can find the ffmepg executable try this one:
<?php
$cmd = 'PATH="/usr/local/bin/"; ffmpeg -i /your/file/destination/batman.mp4 2>&1';
echo "<pre>".shell_exec($cmd)."</pre>";
?>

Using Batik with Yii - Fails in the app but works in terminal

I'm trying to add SVG to .png conversion into my Yii app, using the Batik rasterizing library. Currently I'm working locally on a Mac running OSX 10.6.7, PHP 5.3.4 and Java 1.6.0_24.
When I run the PHP script that deals with the conversion, using...
$output = shell_exec(java -jar batik/batik-rasterizer.jar -m image/png -d pdf_temp/file.png -w 800 pdf_temp/file.svg)
Batik fails with the (unhelpful) error:
About to transcode 1 SVG file(s)
Converting file.svg to pdf_temp/file.png ... file_1310581599.png
Error while converting SVG
However, using...
java -jar batik/batik-rasterizer.jar -m image/png -d pdf_temp/file.png -w 800 pdf_temp/file.svg
...in Terminal works a treat and saves the .png file in the /pdf_temp/ directory along with its original .svg
So what's different about the PHP/apache environment that's causing Batik to fail when Terminal is fine?
EDIT:
After chatting with some colleagues we think it could be the fact that Java needs to run as root - which it does from Terminal but not within the web server.
Adding...
2>&1 1> /dev/null
To my Batik shell_exec() command reveals the following error:
Exception in thread "main" java.lang.InternalError: Can't connect to window server - not enough permissions.
Any ideas as to how I can run Java as root with the web server environment? Or allow it to perform the functions I require?
-Djava.awt.headless=true
http://www.emcken.dk/weblog/archives/25-svg-rasterizer-with-batik.html
I am currently working with Batik and Yii as well. Check the output and the source files' path. I provided the whole path and it is working now. It seems that Yii doesn't stand where your view is, instead Yii current location is your webroot. In my case I fixed like this:
define ('BATIK_PATH', '/var/www/wattquotes/protected/views/calculator/reports/batik/batik-rasterizer.jar');
$typeString = ' -m image/jpeg';
$outfile = ' /var/www/wattquotes/protected/views/calculator/reports/batik/temp/pic.jpg';
$width = ' -w 600';
$tempName = ' /var/www/wattquotes/protected/views/calculator/reports/batik/temp/proposal.svg';
$output = shell_exec("java -jar ". BATIK_PATH ." $typeString -d $outfile $width $tempName");
It works!

PHP exec() Not Working With ffmpeg

I'm attempting to run the following command in PHP (on Ubuntu):
<?php
if (exec("/home/johnboy/ffmpeg/ffmpeg -i test1.mp4 -acodec aac -ab 128kb -vcodec mpeg4 -b 1220kb -mbd 1 -s 320x180 final_video.mov"))
{ echo "Success"; }
else { echo "No good"; }
And I always get "No good" echoed back, and no file created.
Interestingly, if I run the same exact command in Shell, it works, no problems.
Also, when I run the same code above, but subsitute "whoami" instead of the ffmpeg stuff, it works. (It echoes back "Success")
Any ideas on why this wouldn't be working? Thanks.
get the stderr will give the result
try
ffmpeg -i inputfile [more_params] 2>&1
Can the apache/web user reach /home/johnboy/ffmpeg/ffmpeg? That is, perhaps /home/johnboy is 0700 instead of 0755?
Perhaps there are resource limits affecting loading of such a large program and all its libraries?
If you run the script to the php cli sapi, does it behave correctly? Even when running as the apache user?
What does strace -ff show when the apache web user runs the php script through the php cli?
Use this
$ffmpeg = "ffmpeg Installed path";
$flvfile = "source video file with root path";
$png_path " "Destination video file with root path and file type";
exec("$ffmpeg -y -i $flvfile -vframes 1 -ss 00:01:60
-an -vcodec png -f rawvideo -s 110x90 $png_path");
You are using relative paths to the file names. Are you sure you are executing the command in the right directory?
There would be some issues if you want to execute something that way.
1. Maybe you have some permission issue, the webserver have limitation to handle some execution to the system.
2. Maybe your path file is incorrect.
3. you can try to use shell_exec to perform the execution to the system.
Anyway, what I would do to make my execution would go smoothly are,
I will write 2 programs with message passing included between them, for example client server program.
The server would wait some messages from the client to execute some command (all of the command, it would be no permission issues). All you have to do in you web is to call your client application.
What I emphasize is to build some interface from web and the system. It would solve a lot of problem with permission issues.
hope this help.
The function exec() only returns the last line of output, I suspect that the last line of that command is blank. if you want the entire contents of the command you should use shell_exec().
Also keep track of where the command is executing, try: print(shell_exec("pwd"));
Enable safemode and it will work
$output = shell_exec('/home/person/www/ffmpeg 2>&1');
echo "<pre>$output</pre>";
Notice the 2>&1 part ...

Categories