Professional Documents
Culture Documents
<?php
$num_to_guess = 42;
$message = "";
if (!isset($_POST['guess']))
{
$message = "Welcome to the guessing machine!";
}
elseif(!is_numeric($_POST['guess']))
{
$message ="i dont understand that respone";
}
<label for-"File">Filename:</label>
<input type="file" name="file" id="file">
<br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Upload_file.php
<?php
if($_FILES["file"]["error"]>0)
{
echo "error" .$_FILES["file"]["error"] ."<br>";
}
else
{
echo"upload:".$_FILES["file"]["name"] ."<br>";
echo "type=".$_FILES["file"]["type"]."<br>";
echo"size:".$_FILES["file"]["size"] ."<br>";
echo"stored in:".$_FILES["file"]["tmp_name"] ."<br>";
}
?>
OUTPUT
Web.txt
Hello Learners!
Welcome to PHP
3)File read the content
<?php
$file = "web.txt";
// Check the existence of file
if(file_exists($file))
{
// Open the file for reading
$handle = fopen($file, "r") or die("ERROR: Cannot open
the file.");
// Read fixed number of bytes from the file
$content = fread($handle, "200");
<?php
$myfile = fopen("web2.txt", "r") or die("Unable to open
file!");
// Output one line until end-of-file
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
?>
</body>
</html>
5) File copy to sub directory
Create upload directory then
Example.txt
i love india
filecopy.php
<?php
// Source file path
$file = "example.txt";
// Destination file path
$newfile = "duplicate.txt";
// Check the existence of file
if(file_exists($file))
{
// Attempt to copy file
if(copy($file, $newfile))
{
echo "File copied successfully.";
}
else
{
echo "ERROR: File could not be copied.";
}
}
else
{
echo "ERROR: File does not exist.";
}
OUTPUT
7) File deleted
<?php
unlink('duplicate.txt');
echo "File deleted successfully";
?>
8) Written into a file
<?php
$file = "note.txt";