PHP Tutorial-File Read
PHP-File Open: read
Before we can information from a file we have to use the function fopen to open the file for reading. Here's the Code to read- Open the File we created in the PHP file Write Lessons.
PHP Code:
The file we created in the last lesson was names "test1.txt". Your PHP script that you are writing should reside in the same directory as "test.txt"
My Video
Code 1:
<html>
<head>
</head>
<body>
<h1> Knowledge Edcuation Cambodia </h1>
<form method="post" enctype="multipart/form-data" action="readdata.php">
<input type="file" name="myfile">
<input type="submit" value="readdata">
</form>
</body>
</html>
Note: File->Save->index.php
Code 2:
<?php
$myfile=$_FILES["myfile"];
$path=$myfile["tmp_name"];
$type=$myfile["type"];
if($type=="text/plain"){
if(file_exists($path)){
if(is_readable($path)){
$object=fopen($path,"r");
while(!feof($object))
{
$line=fgets($object);
$line=htmlspecialchars($line);
echo $line;
echo "<br/>";
}
}
else
{
echo "the file is not reading format";
}
}
else{
echo "file not Exits";
}
}
else
{
echo "No text file";
}
?>
Note: file->save-readdata.php