How to read data from a file stored in XAMPP webserver using PHP ? Last Updated : 01 Dec, 2020 Comments Improve Suggest changes Like Article Like Report We have given a file stored on XAMPP server and the task is to read the file from server and display the file content on the screen using PHP. We use some PHP functions to solve this problem. File: A file is set of data stored in a disk in different formats. For example - .txt, .exe, .pdf etc fopen() function: The fopen() function in PHP is an inbuilt function which is used to open a file or a URL. It is used to bind a resource to a steam using a specific filename. The filename and mode to be checked are sent as parameters to the fopen() function and it returns a file pointer resource if a match is found and a False on failure. The error output can be hidden by adding an ‘@’ in front of the function name. Syntax: fopen('filename', filemode) Here, file name is name of the file and file mode includes read(r) mode, write(w) and binary(b) mode etc. fopen($geek, r) — Here we are opening geek file in read mode.fopen($geek, r+) — Here we are opening geek file in read and write mode.fopen($geek, w) — Here we are opening geek file in write mode.fopen($geek, w+) — Here we are opening geek file in read and write mode.fopen($geek, b) — Here we are opening geek file in read and write mode. Requirements: XAMPP web server — If you have not installed XAMPP/WAMP web server then please install it by using the following steps: Link to install: https://www.apachefriends.org/download.html Start the XAMPP Server Open the notepad and type the below code: PHP <?php // File to be read $file = "./welcome.txt"; // Opening file $f = fopen($file, "r") or exit("Unable to open file!"); // Read file line by line until // the end of file (feof) while(!feof($f)) { echo fgets($f)."<br />"; } // Closing file fclose($f); ?> Data in welcome.txt file are: GEEKS FOR GEEKS IS BEST FOR COMPUTER SCIENCE Place these two files in folder (Path is show here) Path Running the Script Type the following URL in the browser: localhost/gfg/1.php Output: Comment More infoAdvertise with us Next Article How to read data from a file stored in XAMPP webserver using PHP ? sravankumar_171fa07058 Follow Improve Article Tags : Web Technologies PHP PHP Programs PHP-Misc Similar Reads How to execute PHP Script in Website using XAMPP webserver ? First we have to install the XAMPP/WAMP webserver in our system. Please follow the link to download and install XAMPP/WAMP server. Link https://www.apachefriends.org/download.html After successful installation, the steps we should follow are- Open XAMPP control panel, if you want to link database to 2 min read PHP program to fetch data from localhost server database using XAMPP In this article, we will see how we can display the records by fetching them from the MySQL database using PHP. Approach: Make sure you have an XAMPP server or WAMP server installed on your machine. In this article, we will be using the XAMPP server.XAMPP is a free and open-source cross-platform web 4 min read How to Export data to CSV file from Database using XAMPP ? In this article, we are going to load the data present in the database (MySQL) into CSV file. Display the data in the database and also export that data into CSV file. We are using XAMPP tool to store locally in a database. XAMPP stands for  cross-platform, Apache, MySQL, PHP, and Perl. It is among 3 min read How to display XML data in web page using PHP ? In this article, we are going to display data present in an XML file on a web page using PHP through the XAMPP server. PHP is a server-side scripting language that is mainly for processing web data. The XML stands for an extensible markup language. Requirements: XAMPP server Syntax: <root> 2 min read How to post data using file_get_contents in PHP ? The file_get_contents() function in PHP is used to read the contents of a file and make HTTP requests using GET and get HTTP responses using POST methods. The HTTP POST request can be made using the $context parameter of the file_get_contents() function, which posts the specified data to the URL spe 3 min read How to Display Data from CSV file using PHP ? We have given the data in CSV file format and the task is to display the CSV file data into the web browser using PHP. To display the data from CSV file to web browser, we will use fgetcsv() function. Comma Separated Value (CSV) is a text file containing data contents. It is a comma-separated value 2 min read How to copy a file from one directory to another using PHP ? The copy() function in PHP is used to copy a file from source to target or destination directory. It makes a copy of the source file to the destination file and if the destination file already exists, it gets overwritten. The copy() function returns true on success and false on failure. Syntax: bool 2 min read How to open a PDF files in web browser using PHP? Opening a PDF file in a web browser using PHP involves serving the PDF directly to the clientâs browser. This is achieved by setting the appropriate HTTP headers (Content-Type and Content-Disposition) in PHP, which instructs the browser to display the PDF instead of downloading it.Note: PHP doesn't 2 min read How to Insert Form Data into Database using PHP ? In modern web development, Handling User Input is a fundamental task. One of the most common Operations is capturing data from a form and inserting it into database. PHP, combined with MySQL, offers a straightforward and powerful way to achieve it.Here, we will see complete process of inserting form 4 min read How to get return text from PHP file with ajax ? In this article, we will see how to get return the text from the PHP file with ajax. Ajax is an acronym for Asynchronous JavaScript and XML is a series of web development techniques that build asynchronous web applications using many web technologies on the client-side. Without reloading the web pag 2 min read Like