cherault
-
Posts
23 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by cherault
-
-
Hi Dsonesuk, Thanks for your directive, but I don't know how to do that.
Could you please give me a guidance according Javascript/PHP to take the value of the slider, and write it to my local disk ?Thanks
-
Dear all,
In my project, I am using an emebedded webserver LIGHTTPD with PHP.
Within the main webpage, I use slider to write its value within a local file on my Linux OS.I wrote the slider like this:
<input type="range" name="lightInputName" id="lightInputId" value="1" min="1" max="20" onchange="getvalor(this.value);" oninput="lightOutputId.value = lightInputId.value"> <input size="1" type="text" name="lightOutputName" id="lightOutputId"></input>
What I want to do is to know if a javascript and/or PHP script is able to read the value of the slider, and copy it onto a local file.
I don't have any idea on how to do this.
Many thanks for your guidance.
Best regards,
-
Thank you for the informations.
-
Unfortunately it doesn't work !
Even if I put the files inside /var/www/html...no luck.What kind of permissions do I need to set to be able to activate a shell script which will launch a program outside /var/www/html ?
-
At least, one question:
Using the base of the php script for writing a file, and using the same HTML page:
PHP (test.php):
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $myfile = fopen("file.txt", "w") or die("Unable to open file!"); $txt = "writing test\n"; fwrite($myfile, $txt); fclose($myfile); ?>
HTML (index.html):
<!DOCTYPE html> <html> <head> <style> </style> </head> <body> <form action="test.php" method="POST"> <input type="submit" name="Envoyer" value="Open Script"> </form </body> </html>
I tried to modify the PHP file to launch a shell script :
SHELL (test.sh)
#!/bin/bash cd /home/$USER/Prog/C++/Debug/ ./test exit 0
So my PHP file look like this:
PHP (test.php)
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); exec("test.sh"); header('Location: http://localhost/index.html?success=true'); ?>
But it doesn't work !
I have the same permissions as before, so the rights access are corrects.
So I think it comes from the PHP script, but I don't know why it doesn't work.Do you have an idea ?
Thanks for all
-
Ok, some news from my tests:
I did that:
sudo usermod -a -G www-data <user> sudo chgrp -R www-data /var/www/html/ sudo chmod -R g+w /var/www/html/
After these modifications, when I launch the php script, I saw :
Notice: Use of undefined constant - assumed '' in /var/www/html/test.php on line 9
But the file was written in /var/www/html
So I can say this solve the problem partially.Whatever, Thank you to all of you for your time, help and support
Regards,
-
Hi Luisrosety,
Thank you for the help.
I did all the steps you gave me, but no luck.
Who is the user in /home/pi/www/test ?
Is it root or www-data ?Actually, I delete and reinstall lighttpd and php7.0.
The actual permissions and owner are root.
Do I need to move to www-data like that :sudo chown -R www-data:www-data /var/www/html
or
sudo chown -R <user>:www-data /var/www/html
-
Thanks Ingolme for the info. But it doesn't solve my problem.
I am sure the HTML and PHP code are correct.
When I launch the PHP in console mode, everything works fine.But when I launch it through HTML...nothing happen.
So, I suppose there is some problems with the permissions, of Firefox is blocking something....I really don't know.
I just want to activate a shell script from an html button...I must be easy no ?
-
Thanks Luisrosety,
I did it but nothing appears...
The php script is :
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); exec("/home/$USER/script"); ?>
Is it possible that the web browser (Firefox) block some informations ?
-
Ok, I tried your solution like this:
<?php $myfile = fopen("/var/www/html/newfile.txt", "w") or die("Unable to open file!"); $txt = "testwriting\n"; fwrite($myfile, $txt); fclose($myfile); ?>
The HTML file is like that:
<!DOCTYPE html> <html> <head> <style> </style> </head> <body> <form action="openApp.php"> <input type="submit" name ="value" value="Open Script"> </form </body> </html>
But it still doesn't work.
The access are the next:
-rw-r--r-- 1 www-data www-data 173 déc. 6 12:53 index.html -rw-r--r-- 1 www-data www-data 0 déc. 6 12:34 newfile.txt -rwxrwxr-x 1 www-data www-data 174 déc. 6 13:06 openApp.php
What do you think about this ?
-
Ok, doesn't work...I don't what to do.
I though it xas simple to build an HTML interface to write some data within a text file, but it isn't !!!!
This is why I love C++ 😉More seriously, is there is a way to understand what's going on with HTMl and PHP.
I admit i'm really stuck with that !!!Thanks for your help and support
-
Thanks dsonesuk, I will get a try to see what is going on
-
This is the logs...I have some problems with the rights access:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME lighttpd 716 www-data cwd unknown /proc/716/cwd (readlink: Permission denied) lighttpd 716 www-data rtd unknown /proc/716/root (readlink: Permission denied) lighttpd 716 www-data txt unknown /proc/716/exe (readlink: Permission denied) lighttpd 716 www-data NOFD /proc/716/fd (opendir: Permission denied)
-
Not yet, but I will do it asap.
Thanks for the info
-
I tried your solution, but I am stuck with that.
Nothing works !
If my HTML page is like that with the post method:
<form action="openApp.php" method="post"> <input type="submit" value="Open Script"> </form>
Is that correct to call the PHP script ?
Or maybe using type=button is better than submit ?All the files (HTML, SHELL and PHP) are managed by the www-data user.
Is that correct too ?Another point:
When I go to /var/www/html, and launching just my PHP script:
cd /var/www/html php openApp.php
the script works fine, and write something in a file text like this:
<?php $myfile = fopen("/home/$USER/file.txt", "w") or die("Unable to open file!"); $txt = "writing test\n"; fwrite($myfile, $txt); fclose($myfile); ?>
But when I use the HTML page, nothing works.
So I deduce that is a permission access problem right ?
Because the PHP script works, and the HTML works too.
So, where I am wrong ? -
Thanks for your reply and proposition.
Unfortunately, it doesn't work.
I am not using Apache but Lighttpd, I think it is similar.
Do you know how to check the safe mode in PHP ?
Is it in php.ini ?I will check that point and get back to you.
One more time thanks.
-
Hi all,
Working with:
- Linux Debian
- Lighttpd Server
- PHP7.0
I want to launch some shell scripts pressing HTML buttons. All the files are placed in /var/www/html The rights are done by:
sudo chown www-data:www-data /var/www/
So, I wrote a very simple code:
HTML test code (index.html):
<form action="openApp.php"> <input type="submit" value="Open Script"> </form>
PHP test code (openApp.php):
<?php exec('test.sh'); header('Location: http://localhost/index.html?success=true'); ?>
But no luck, nothing is working.
Note that the shell script just create an empty file like that:
touch /home/$USER/testFile
Also, my Lighttpd configuration file is like that:
server.modules = ( "mod_access", "mod_alias", "mod_compress", "mod_fastcgi", "mod_redirect", )
May be I am wrong with that piece of code. Do I need some Javascript to do the job ? May be the rights are wrong ?
Could you help me please ? I am stuck with that.
Thank you for your help and support
-
Dear all,
I am using a slider to change an integer value.
My question is how to write this changed value to a text file in my computer ?This is the code I use to change the value slider:
<form name="lightValues"> <input type="range" name="lightInputName" id="lightInputId" value="1" min="1" max="20" onchange="getvalor(this.value);" oninput="lightOutputId.value = lightInputId.value"> <input size="1" type="text" name="lightOutputName" id="lightOutputId"></input> </form>
Thanks for your help and support.
Best regards,
-
Ok, thanks Smus.
Is it possible to do that with node.js ?
If yes how ?Regards,
-
Thanks Ingolme,
So I can't call a shell script from Javascript. But from PHP it is possible, so why not whith Javascript ?
I don't understand why, but it's ok, I will find a solution. I don't want to use PHP. May be there is another solution.Regards,
-
Dear all,
I managed a web interface under Linux/Apache.
This interface must start and stop some shell scripts, through HTML buttons.My goal is to use just only one HTML button to do 3 actions:
1- Stop a shell script
2- Open a new HTML page
3- Start a new shell scriptSo, usually, I will drive it like this:
<script language="javascript"> function button() { function1(); function2(); function3(); } </script>
But my problem is what kind of Javascript function is able to start and stop a shell script ?
I found various answer with PHP, but I don't want use it ! Just HTML/JAVASCRIPT.Can you please help me ?
Thank you for your support and help.
Best regards,
-
Dear all,
Using a small webpage for my app, I am confused because I don't how to stop the function I did.
I am using a C++ program which grab pictures in a file.
I read the file and update it each 2 seconds.The functions I used are:
<script language="javascript"> function updateImage() { obj = document.imagename; obj.src = obj.src + "?" + Math.random(); setTimeout("updateImage()",2000); } </script> <script language="javascript"> function showPicture() { var sourceOfPicture = "/home/tux/Prog/Medias/Images/calib1.png"; var img = document.getElementById('bigpic') img.src = sourceOfPicture.replace('90x90', '225x225'); img.style.display = "block"; } </script>
And I call them like this:
<h1>Camera Preview</h1> <button onclick="showPicture()">Start Preview</button><br><br> <body onload="updateImage()"> <img style="display:block;" id="bigpic" src="bigpic" name="imagename" width="340" height="240">
Can you tell me how can I do to add a "stop" button to stop the update, and conserving the last image on screen ?
Thank you for your help and support.
Best regards,
PHP problem with local files
in PHP
Posted · Edited by cherault
Dear all,
I am working on an embedded Linux platform with Lighttpd and PHP-7.0.
My goal is using some HTML button and sliders to write some values on a local file.
For example, if I click on a HTML button, I want to create and write a text file located in /home/$USER/
To do that, I build some files
HTML
PHP
SHELL BASH
#!/bin/bash cd /home/$USER/ touch testFile && echo "This is a test" > testFile
So, when I launch the Shell Script like this:
cd /var/www/html ./test.sh
It works fine, and when I launch the PHP script like this:
cd /var/www/html php test1.php
It works also.
My problem is when I want to launch it through the webpage...it doesn't works.
I think because I have some wrong permissions, so I did this:
sudo usermod -a -G www-data $USER sudo chgrp -R www-data /var/www/html sudo chmod -R g+w /var/www/html
But no luck, I still doesn't work.
Do you have an idea of the problem ?
Thanks for your help and support.
Regards,