PHP File Handling

PHP File Handling In Hindi – File Handling Function in Hindi

PHP

PHP File Handling In HindiFile Handling Function in Hindi:- File Handling In PHP Mai Bahut Hi Important Part Hota Hai And PHP Mai File Handling Mai Creating file, Opening file, Reading file, Writing File, Closing file or Deleting file Jaise Kaam Kar Sakte Hai |

Yadi Aapne  HTML Full Course  And CSS Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

Ham Is File Handling Chapter Mai Is text file, “masterprogramig.txt“, Ka Istemal Karenge |

PHP File Handling In Hindi

File Handling Ek Important Part Hota Hai kisi Bhi Web Application Ka And Isme Keval Aapko File Ko Open And Process Karne Ke Bad Aap Is File Handling Se Different Tasks Kar Sakte Hain |

PHP Mai File Ke Sath Har Ek Kaam Ke Liye Alag-Alag File Ke Liye Functions Bananye Gaye Hain |

  • fopen() : Opening File
  • fwrite() : Writing or Creating File
  • fread() , readfile() , filesize(): Reading File
  • fclose() : Closing File
  • unlink() : Deleting File

fclose() : Is Functions Ka Istemal Keval File ko Close Karne Ke Liye Hota Hain |

PHP fopen Functions in Hindi

fopen Function ko Keval PHP Mai File Ko Open Karne Ke Liye Istemal Kiya Jata Hain And fopen Functions Mai 2 parameter pass Karte Hai |

Syntax:

fopen("file_name", "mode");
  • “file_name” : Jis file Ko open Karna Hai Us File Ka Name Yaha Par Input Kiya Jata Hai |
  • mode : Jis mode Par Is file Ko open Karna Hai Wo mode Yaha Par Aata Hai |

PHP File Modes in Hindi

ModesDescription
rfile Ko read Kiya Jata Hai |
r+file Ko read or write Kiya Jata Hai|
wfile par data write Kiya Jata Hai| Agar file already Nhi Hoti To Use Create Kiya Jata Hai | Yaha Par file Mai Pahle store Hua data clear Kiya Jata Hai |
w+file Ko read Or write Kiya Jata Hai | Lekin file already Nhi Hoti To Use create Kiya Jata Hai | Yaha Par file Mai Pahle store Hua data clear Kiya Jata Hai |
afile Ko write Kiya Jata Hai | Agar file Mai already data Hota Hai To Diye Hue data Ko add Kiya Jata Hai| Agar file already Nhi Hoti To Use create Kiya Jata Hai |
a+file Ko read Or write Kiya Jata Hai | Agar file Mai already data Hota Hai To Diye Hue data Ko add Kiya Jata Hai| Agar file already Nhi Hoti To Use create Kiya Jata Hai |
xfile ko write Kiya Jata Hai | Agar file already Waha Par Hoti Hai To ‘File exist’ Ka error Aa Jata Hai |
x+file Ko read Or write Kiya Jata Hai | Agar file already Waha Par Hoti Hai To ‘File exist’ Ka error Aa Jata Hai |

Example:

<?php
$open = fopen("masterprograming.txt", "r");
?>

PHP fwrite Function In Hindi

fwrite() Function In PHP se file par data write Kiya Jata Hai| Agar file already Nhi Hoti To Use Create Kiya Jata Hai |

Syntax:

fwrite(file, "string", length_in_bytes)

Parameters :

  • file : Jis file Par write Karna Hai Us File Ko Open Kiya Jata Hai|
  • “string”: Jisko write Karna Hai Yaha Par Wo String Diya Jata Hai|
  • length_in_bytes: Ye optional Rahta Hai |Yaha Par bytes ke Number And Ye Bytes ki length return Karta hai |

Example:

<?php 
$file = fopen("masterprograming.txt", "w");
echo fwrite($file, "Hello World");
fclose($file)
 ?>

Output:

11

masterprograming.txt

Hello World!

fwrite() function using Length

Source Code :

<?php 
$file = fopen("masterprograming.txt", "w");
echo fwrite($file, "Hello World",8);
fclose($file)
 ?>

Output :

8

masterprograming.txt

Hello Wor

PHP fread Function In Hindi

fread() Function in PHP Ka Istemal Keval File se Data Ko Read Karne Ke Liye Kiya Jata Hain |

Syntax:

fread(file, length_in_bytes)
  • file: Jis file Ko read Karna Hai Us file Ko open Kiya Jata Hai |
  • length_in_bytes: Jinte bytes read Karne Hai Unki Number Aate Hai |

Example:

<?php 
$file = fopen("masterprograming.txt", "r");
$readdata = fread($file,8);
echo $readdata;
fclose($file)
 ?>

Output:

Hello Wo

PHP filesize Function in Hindi

Agar Aap Puri File Ka Data Read Karna Chahte Hoto PHP Main Length Of Butes Ke Liye filesize() function ka istemal Kar Sakte Hain And filesize() function in PHP file ke number of bytes ko return Karta hain |

Syntax:

filesize(file_name);

Example:

<?php
$file = fopen('masterprograming.txt', 'r') or die("File can't opened..");
$file_size = filesize("masterprograming.txt");

$content = fread($file, $file_size);
echo $content;
?>

Output:

Hello World

PHP readfile Function in Hindi

readfile() function in php se Aap file Ko direct read karke file ko print kara sakte hain And Ye Character length bhi print karta hain |

Example:

<?php
echo readfile("masterprograming.txt")
?>

Output:

Hello World11

PHP File Delete Function In Hindi

File Ko Delete Karne Ke Liye PHP Mai unlink() Funtions Ka Istemal Kiya Jata Hain |

Example:

<?php
$delete = unlink("masterprograming.txt");  
if($delete){  
	echo "File deleted successfully.";
}else{  
	echo "Error deleting file."; 
}  
?>  

Output:

File deleted successfully.

File Handling Function in PHP in Hindi

Yadi Aapne  HTML Full Course  And CSS Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

  • The fgets() the function is used to read a single line from a file.
  • The fgetc() the function is used to read a single character from a file.
  • The feof() function checks if the “end-of-file” (EOF) has been reached.
  • The feof() the function is useful for looping through data of unknown length.

Leave a Reply

Your email address will not be published. Required fields are marked *