How do you read or write a file on the server from PHP? Give an example

How do you read or write a file on the server from PHP? Give an example


How do you read or write a file on the server from PHP? Give an example

Answer:
  1. fopen("filename.txt","mode"):- Used for opening file in desired mode, it takes 2 attribute, file name and mode(reading,writing).It is also used to create file.
  2. fread(filename, no of character):- Used to read file takes two attribute file name and number of character we want to read.
  3. fclose(filename):- Used to close file.
  4. fwrite(filename,writing content):- Used to write file 

Code for Reading File in server.


<?php

echo"Read File:";

$handler = fopen("file.txt","r");
fread($handler,20);
fclose($handler);
?>

Steps for Reading File in Server:

step1: create a file using fopen with arguments as a file name with .txt extension and mode with which you want to open the file (here reading) and store the file in some variable to access later.

Step2: Read file using fread with arguments as a file name which is a variable we have assigned to a file name earlier and no of characters we want to read.

step3: Close the file with an argument as a file name which is a variable we have assigned to a file name earlier.

Code for writing File in server.


<?php

echo"Write File:";

$handler = fopen("file.txt","w");
fwrite($handler,20);
fclose($handler);
?>

Steps for Writing File in Server:

step1: create a file using fopen with arguments as a file name with .txt extension and mode with which you want to open the file (here writing) and store the file in some variable to access later.

Step2: Write file using fwrite with arguments as a file name which is a variable we have assigned to a file name earlier and no of characters we want to write.

step3: Close the file with an argument as a file name which is a variable we have assigned to a file name earlier.

Visitor Counter in PHP Video Tutorial (similar video)


Other Question With Answer


















7 comments:

  1. Run 3 Unblocked amazing Free Online Game. It's Run 3 Free Online Game just for Run 3 Game Lovers. You are going to have a great fun via Run 3 unblocked ... run 3 unblocked games

    ReplyDelete
  2. прогон сайта по сайтам прогон сайта результат

    ReplyDelete
  3. автошкола владивосток автошкола владивосток цены 2023

    ReplyDelete
  4. https://simintech.ru/forum/?PAGE_NAME=profile_view&UID=991 сортировка мусора на алтуфьевском шоссе

    ReplyDelete

For Query and doubts!

Powered by Blogger.