ওয়েব application এর জন্য ফাইল handiling একটি গুরত্তপূর্ণ ব্যাপার।
php readfile() function
আমরা একটা টেক্সট ফাইল কে পিএইচপি ফাইল এর মধ্যে read করাব। মনে করি webdictionary.txt নামের একটি টেক্সট ফাইল এ টাইপ করা আছে
AJAX = Asynchronous JavaScript and XML CSS = Cascading Style Sheets HTML = Hyper Text Markup Language PHP = PHP Hypertext Preprocessor SQL = Structured Query Language SVG = Scalable Vector Graphics XML = EXtensible Markup Language
যদি আমরা পিএইচপি দিয়ে কল করি
< ?php
echo readfile("webdictionary.txt");
?>
এই ভাবে কোড লিখতে হবে
PHP fopen() – ফাইল খোলা
যদি আমরা fopen() ফাংশন ব্যবহার করি
< ?php
$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
/*ফাইল যদি directory তে থাকে তাহলে ওপেন করবে এবং read করবে*/
echo fread($myfile,filesize("webdictionary.txt"));
fclose($myfile);
?>
যদি আমরা কোন নতুন ফাইল তৈরি করতে চাই
$myfile = fopen(“testfile.txt”, “w”)
যদি একটি ফাইল এ কিছু লিখতে চাই
< ?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
/*fopen ফাইল ওপেন করবে*/
$txt = "John Doe\n"; /*যেই টেক্সট টি লিখবে তা declare করা হল $txt নামে*/
fwrite($myfile, $txt); /*ফাইল এর মধ্যে লিখবে*/
$txt = "Jane Doe\n";
fwrite($myfile, $txt); /*ফাইল এর মধ্যে লিখবে*/
fclose($myfile); /*এবং ফাইল ক্লোজ হবে*/
?>
