How do you read or write a file on the server from PHP? Give an example
Answer:
- 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.
- fread(filename, no of character):- Used to read file takes two attribute file name and number of character we want to read.
- fclose(filename):- Used to close file.
- 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
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прогон сайта по сайтам прогон сайта результат
ReplyDeleteавтошкола владивосток автошкола владивосток цены 2023
ReplyDeletehttps://polystarsomalia.com/ 1xbet version
ReplyDeleteбесплатные знакомства объявления знакомства
ReplyDeletehttps://simintech.ru/forum/?PAGE_NAME=profile_view&UID=991 сортировка мусора на алтуфьевском шоссе
ReplyDeleteпродвижение сайта вечными ссылками продвижение сайта ссылками
ReplyDelete