Open text file on rasbperrypi using PhP

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I'm trying to open a simple text file on my raspberry pi using PhP. This is the code:




php
$myfile = fopen("/home/pi/Desktop/hello.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("/home/pi/Desktop/hello.txt"));

fclose($myfile);

body>
html>

I saved the above code as .php and opened it on the web browser by typing the raspberry pi IP address and the file name i.e. 192.168.0.17/hi.php yet the web browser is saying "Not Found". I also installed sudo apt-get install apache2 php5 , sudo apt-get install lighttpd php5sudo apt-get install git-core, and cloned the Wiring PI.

Can some one tell me if I'm doing anything wrong please? Thanks

profilepic.png
manpreet 2 years ago

I agree with MartinMarty in my experience using apache..the original file by default was /var/www/html. After downloading PHP I had to change the HTML to PHP. I did this by typing

Sudo nano /var/www/php5 I then added some simple PHP code to show the date saved the file usomg control x Y Enter Then from the terminal I had to remove /var/www/HTMl I then type ls to verify it is gone revisit the ip address hit refresh and you should see the date and the file will be php

I hope this helps..it worked for me


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.