I try to use/call Scilab with php. I followed instruction form https://www.ibm.com/developerworks/library/os-php-scilab/os-php-scilab-pdf.pdf but I cant make it work. I tried listing 1 and what I got is Array (). do I need to save sci/sce file in root folder before calling them in php? is Scilab can be called directly as the instruction?
I had exactly the same problem. I use scilab 6.0.1
This code works for me :
<?php
$path = 'C:\\wamp64\\apps\\scilab-6.0.1\\bin\\';
$path_script = 'C:\\wamp64\\www\\tests\\log.sce';
$command = $path.'WScilex-cli.exe -nb -f '.$path_script;
echo $command;
exec($command, $output);
echo '<pre>';
print_r ($output);
echo '</pre>';
?>
In the log.sce file, I saw matrix on firefox web page, save file and picture on my folder.
Best regards
Related
I have Apache 2 and PHP installed on a Raspberry Pi 1 B+ (RASPBIAN STRETCH LITE
). I have a website running on it with a textbox and a PHP script that is supposed to save the contents of the textbox to a text file on the server when the user submits.
I tryed basically everything but the php script just wont save.
PHP does get the textbox-content (I tested it - it works just fine).
This is my PHP:
<?php
include "code/multiPage/topBar.html";
$dir = "/data/searches.txt";
if ($_REQUEST) {
$input = $_REQUEST["search"];
file_put_contents($dir, $input, FILE_APPEND);
}
?>
PHP is working properly aside from this problem.
The folder has read-write permissions for everyone.
I have also tryed to let PHP create its own folder with code similar to this:
if (!file_exists('path/to/directory')) {
mkdir('path/to/directory', 0777, true);
}
PHP can't even do that.
Thanks in advance for any help!
I figured it out. The problem was that the webserver didn't have permission to write to the directory. problem solved by running sudo chown -R www-data var/www/html/data thanks for the help! Have a nice day :D
First just try this separately from other code
<?php
file_put_contents("/data/searches.txt", "bla", FILE_APPEND);
?>
if it's not working try to get a last error
echo print_r( error_get_last ( ), true)
In order to make sure that you can write to the file you can always check if it's writable
if(is_writable($dir))
Also for debugging it's nice to see how much bites was written by file_put_contents
so the final code easy to debug will be like this:
<?php
include "code/multiPage/topBar.html";
$dir = "/data/searches.txt";
if(!is_writable($dir)){
echo "cannot write to file";
}
if (!empty($_REQUEST["search"])) {
$input = $_REQUEST["search"];
$bitecount = file_put_contents($dir, $input, FILE_APPEND);
}
echo $bitecount . " bites were written to the file";
?>
There is a thing. If $_REQUEST["search"]="" or $_REQUEST["search"]=null the if($_REQUEST) will be TRUE anyway
I'm currently creating a php page which does a ssh call with a .rb (ruby) file.
rb file
require 'metainspector'
page = MetaInspector.new("www.hln.be")
puts page.image
When creating a php file with the following code (php):
$cmd = "ruby facescrape.rb";
$last_line = system($cmd, $retval);
echo $last_line . '
echo $retval;
this only returns value 1.
However 2 things :
When running the same command in ssh, it will print the page.image
correctly.
When i change the rb file and for instance set as last line
puts "test"
this value returns correctly with also print correctly with the aboven php code.
I don't get why printing the page.image works in ssh but won't work by using that php code.
Also tried using exec() instead of system().
Thank you in advance!
Kind regards,
Kurt Colemonts
i want to do crypto encryption in php but with the help of cryptoj.jar & one encyption class of java
i have encyption code that is work properly if i put my necessary jar file & java class in the following path
$_SERVER['DOCUMENT_ROOT'];
This is not an issue for local site, but this is not good idea to put libraries on this root on server.
If i created new directory & put this directory in project folder, the code is not work
i am doing the following code on server.
$path = 'java -cp ' . dirname(__FILE__).'/cryptoj.jar; EncryptURLParams "source=BAClubs&identifier=123456×tamp=2014-02-21 09:59:37.498" ';
echo $path; exit;
$last_line = exec($path , $retval);
echo "XCODE=".$last_line; exit;
This code returns me nothing but if i put this on rootpath it gives me output. what is the problem guys..?
i got my answer by myself only
just have to put the libraries in th project's root folder & then simple use the following code
$path = 'java EncryptURLParams "source=BAClubs&identifier=123456×tamp=2014-02-21 10:00:00';
$last_line = exec($path , $retval);
echo "return value--".$retval."<br/>";
echo "XCODE--".$last_line;
i got my output in $last_line variable.
Thanks Guys...
i have a batch file that contains a command to record a live stream from server, i have tried it in CMD.exe, it work fine.
I need now to run this file from php code (by a button "Record"), but i don't get any output.
please can you check my code and try to give me a solution please :
1 - the batch file code :
#echo off
vlc input stream --sout "#duplicate{dst=display,dst=std{access=file,mux=mov,dst=output file.mp4}"
#echo off
2 - the php file code:
<?php
$file = file_get_contents("C:\\wamp\\www\\CMD\\filebat.bat");
echo exec($file);
echo "Done!";
?>
3 - Another php code:
<?php
$file = file_get_contents("C:\\wamp\\www\\CMD\\filebat.bat");
$output = exec($file);
print_r($output);
?>
4 - Another php code :
<?php
echo exec('C:\\wamp\\www\\CMD\\filebat.bat');
?>
i tried these 3 php code but i don't get any output.
kindly, can you help me to find the best solution how i Run a batch file from php code ??
regards,
4.) Should work. Check php.ini/phpinfo if SAFE_MODE is OFF.
http://www.php.net/manual/en/function.exec.php
Trying to figure this out. I am trying to execute a perl script within php, using shell_exec() like so:
<?php
$output=shell_exec("./tst.pl > test.txt");
//$output=shell_exec("./tst.pl");
echo $output;
?>
It will not write output to a file using ">" filename.txt.
It will work if I execute without directing it to a filename as I can confirm this with echo.
Does this have to do with using ">"?
Permissions should be fine as I am able to run the same perl script on command line and direct to file. Any suggestions for executing this?
The output of "test.txt" will be used as input:
<?php
$data = array();
$InputFile = file("test.txt");
...
?>
It was definitely a permissions problem. Wrote the file out to /tmp and it worked fine.
<?php
$output=shell_exec("./tst.pl > /tmp/test.txt");
echo $output;
?>