Jump to content

cherault

Members
  • Posts

    23
  • Joined

  • Last visited

cherault's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. 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 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>AI-VISION</title> <style> </style> </head> <body> <form action="test1.php" method="POST"> <input type="submit" value="Open Script"> </form> </body> </html> PHP <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); exec("/bin/bash /var/www/html/test.sh"); ?> 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,
  2. 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
  3. 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,
  4. Thank you for the informations.
  5. 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 ?
  6. 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
  7. 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,
  8. 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
  9. 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 ?
  10. 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 ?
  11. 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 ?
  12. 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
  13. Thanks dsonesuk, I will get a try to see what is going on
  14. 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)
  15. Not yet, but I will do it asap. Thanks for the info
×
×
  • Create New...