Showing posts with label filesystem function example. Show all posts
Showing posts with label filesystem function example. Show all posts

php mkdir() function - how to create a directory programmatically in php

php mkdir() function - how to create a directory programmatically in php


mkdirFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php mkdir() function - how to create a directory programmatically in php</title>
</head>

<body>
    <h2 style="color:HotPink; font-style:italic">
     php mkdir() function example:<br /> how to create a directory
    </h2>
    <hr width="325" align="left" color="Pink" />
    <br />

<?php

 mkdir("testdirectory");
?>
</body>
</html>




php is_writable() function - how to check whether specific file is writable

php is_writable() function - how to check whether specific file is writable


is_writableFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php is_writable() function - how to check whether specific file is writable</title>
</head>

<body>
    <h2 style="color:HotPink; font-style:italic">
     php is_writable() function example:<br /> how to check whether specific file is writable
    </h2>
    <hr width="500" align="left" color="Pink" />
    <br />

<?php
 $file = "test.txt";
 echo "<font style=color:DarkGreen;font-weight:bold;font-size:x-large;>";
 
 if(is_writable($file))
 {
  echo "test.txt is writable";
  }
 else
 {
  echo "test.txt is not writable";
  }
 echo "</font>";
?>
</body>
</html>




php is_readable() function - how to check whether specific file is readable

php is_readable() function - how to check whether specific file is readable


is_readableFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php is_readable() function - how to check whether specific file is readable</title>
</head>

<body>
    <h2 style="color:OrangeRed; font-style:italic">
     php is_readable() function example:<br /> how to check whether specific file is readable
    </h2>
    <hr width="500" align="left" color="Orange" />
    <br />

<?php
 $file = "test.txt";
 echo "<font style=color:Green;font-weight:bold;font-size:large;>";
 
 if(is_readable($file))
 {
  echo "test.txt is readble";
  }
 else
 {
  echo "test.txt is not readble";
  }
 echo "</font>";
?>
</body>
</html>




php is_executable() function - how to check whether specific file is executable

php is_executable() function - how to check whether specific file is executable


is_executableFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php is_executable() function - how to check whether specific file is executable</title>
</head>

<body>
    <h2 style="color:OrangeRed; font-style:italic">
     php is_executable() function example:<br /> how to check whether specific file is executable
    </h2>
    <hr width="530" align="left" color="Orange" />
    <br />

<?php
 
 $file = "test.txt";
 echo "<font style=color:Green>";
  if(is_executable($file))
  {
   echo "file is executable(test.txt)? true";
   }
  else
  {
   echo "file is executable(test.txt)? false";
   }
 echo "</font>";
?>
</body>
</html>




php glob() function - how to get filenames by specific pattern in php

php glob() function - how to get filenames by specific pattern in php


globFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php glob() function - how to get filenames by specific pattern in php</title>
</head>

<body>
    <h2 style="color:OrangeRed; font-style:italic">
     php glob() function example:<br /> how to get filenames by specific pattern
    </h2>
    <hr width="530" align="left" color="Orange" />
    <br />

<?php
 echo "<font style=color:Green>all .txt files: </font>";
 print_r(glob("*.txt"));

 echo "<br /><br />";
 echo "<font style=color:Green>all .php files: </font>";
 print_r(glob("*.php"));
?>
</body>
</html>




php ftruncate() function - how to truncate an open file in php

php ftruncate() function - how to truncate an open file in php


ftruncateFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php ftruncate() function - how to truncate an open file in php</title>
</head>

<body>
    <h2 style="color:Crimson; font-style:italic">
     php ftruncate() function example:<br /> how to truncate an open file in specific length
    </h2>
    <hr width="510" align="left" color="Orange" />
    <br />

<?php

 $file = "truncatedfile.txt";
 echo "file size(truncatedfile.txt):" . filesize($file);
 
 // open the file
 $file=fopen($file,"a+") or exit("unable to open file!");
 ftruncate($file,25);
 
 echo "<br />file truncated...<br />"; 

 //close the file.
 fclose($file);
 clearstatcache();

 echo "file size(truncatedfile.txt):" . filesize("truncatedfile.txt");

?>
</body>
</html>




php ftell() function - how to get the current position in an open file in php

php ftell() function - how to get the current position in an open file in php


ftellFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php ftell() function - how to get the current position in an open file in php</title>
</head>

<body>
    <h2 style="color:SeaGreen; font-style:italic">
     php ftell() function example:<br /> how to get the current position in an open file
    </h2>
    <hr width="475" align="left" color="Green" />
    <br />

<?php

 // open the file in readonly mode.
 $file=fopen("test.txt","r") or exit("unable to open file!");
 
 echo "<font style=color:red>";
 //output current position
 echo "current position: " . ftell($file) . "<br />";
 
 //move pointer
 fseek($file,10);
 echo "move pointer...<br />";
 
 //output current position
 echo "current position: " . ftell($file);
 
 echo "</font>";
 //close the file.
 fclose($file);

?>
</body>
</html>




php fstat() function - how to get information about an open file in php

php fstat() function - how to get information about an open file in php


fstatFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php fstat() function - how to get information about an open file in php</title>
</head>

<body>
    <h2 style="color:OrangeRed; font-style:italic">php fstat() function example:<br /> how to get information about an open file</h2>
    <hr width="475" align="left" color="Orange" />
    <br />

<?php

 // open the file in readonly mode.
 $file=fopen("test.txt","r") or exit("unable to open file!");
 
 print_r(fstat($file));
 
 //close the file.
 fclose($file);

?>
</body>
</html>




php fseek() function - how to moves the file pointer in php

php fseek() function - how to moves the file pointer in php


fseekFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php fseek() function - how to moves the file pointer in php</title>
</head>

<body>
    <h2 style="color:OrangeRed; font-style:italic">
     php fseek() function example:<br /> how to moves the file pointer from current position to new position
    </h2>
    <hr width="475" align="left" color="Orange" />
    <br />

<?php

 // open the file in readonly mode.
 $file=fopen("test.txt","r") or exit("unable to open file!");
 
 //output current position
 echo "current position: " . ftell($file) . "<br />";
 
 //move pointer
 fseek($file,10);
 echo "move pointer...<br />";
 
 //output current position
 echo "current position" . ftell($file);
 
 //close the file.
 fclose($file);

?>
</body>
</html>




php fread() function - how to read from an open file in php

php fread() function - how to read from an open file in php


freadFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php fread() function - how to read from an open file in php</title>
</head>

<body>
    <h2 style="color:DeepPink; font-style:italic">php fread() function example:<br /> how to read from an open file</h2>
    <hr width="325" align="left" color="Pink" />
    <br />

<?php

 // open the file in readonly mode.
 $file=fopen("test.txt","r");
 
 echo fread($file,8);
 
 //close the file.
 fclose($file);

?>
</body>
</html>




php fputs() function - how to write an open file in php

php fputs() function - how to write an open file in php


fputsFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php fputs() function - how to write an open file in php</title>
</head>

<body>
    <h2 style="color:OrangeRed; font-style:italic">php fputs() function example:<br /> how to write an open file</h2>
    <hr width="325" align="left" color="Orange" />
    <br />

<?php

 // open the file
 $file=fopen("testfputs.txt","w");
 
 echo fputs($file,"text writen by fputs function.");
 
 //close the file.
 fclose($file);

?>
</body>
</html>




php fopen() function - how to open a file in php

php fopen() function - how to open a file in php


fopenFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php fopen() function - how to open a file in php</title>
</head>

<body>
    <h2 style="color:Crimson; font-style:italic">php fopen() function example: how to open a file</h2>
    <hr width="510" align="left" color="Orange" />
    <br />

<?php

 // open the file in readonly mode.
 $file=fopen("test.txt","r") or exit("unable to open file!");
 
 //start reading the file line by line.
 while (!feof($file))
 {
  echo  fgets($file). "<br/>";
  }


 //close the file.
 fclose($file);

?>
</body>
</html>




php filetype() function - how to get file type in php

php filetype() function - how to get file type in php


filetypeFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php filetype() function - how to get file type in php</title>
</head>

<body>
    <h2 style="color:DarkGreen; font-style:italic">php filetype() function example:<br /> how to get file type</h2>
    <hr width="350" align="left" color="OrangeRed" />
    <br />

<?php

 $file = "test.txt";
 echo "<h3 style=color:OliveDrab>";
  echo "file type (test.txt) : ";
  echo  filetype($file);
 echo "</h3>";
?>
</body>
</html>




php filesize() function - how to get file size in php

php filesize() function - how to get file size in php


filesizeFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php filesize() function - how to get file size in php</title>
</head>

<body>
    <h2 style="color:Olive; font-style:italic">php filesize() function example:<br /> how to get file size</h2>
    <hr width="350" align="left" color="Orange" />
    <br />

<?php

 $file = "test.txt";
 echo "<h3 style=color:Red>";
  echo "file size (test.txt) : ";
  echo  filesize($file);
 echo "</h3>";
?>
</body>
</html>




php fileperms() function - how to get permissions status for a file in php

php fileperms() function - how to get permissions status for a file in php


filepermsFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php fileperms() function - how to get permissions status for a file in php</title>
</head>

<body>
    <h2 style="color:Crimson; font-style:italic">php fileperms() function example:<br /> how to get permissions status</h2>
    <hr width="350" align="left" color="OrangeRed" />
    <br />

<?php

 $file = "test.txt";
 echo "<h3 style=color:Tan>";
  echo "file purmissions (test.txt) : ";
  echo  fileperms($file);
 echo "</h3>";
?>
</body>
</html>




php filemtime() function - how to get file content last modified time in php

php filemtime() function - how to get file content last modified time in php


filemtimeFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php filemtime() function - how to get file content last modified time in php</title>
</head>

<body>
    <h2 style="color:SeaGreen; font-style:italic">php filemtime() function example:<br /> how to get file last modified time</h2>
    <hr width="375" align="left" color="LawnGreen" />
    <br />

<?php

 $file = "test.txt";
 echo "<h3 style=color:Magenta>";
  echo "file content last modified (test.txt) : ";
  echo  date("F d Y H:i:s", filemtime($file));
 echo "</h3>";
?>
</body>
</html>




php filectime() function - how to get file last change time in php

php filectime() function - how to get file last change time in php


filectimeFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php filectime() function - how to get file last change time in php</title>
</head>

<body>
    <h2 style="color:DodgerBlue; font-style:italic">php filectime() function example:<br /> how to get file last change time</h2>
    <hr width="375" align="left" color="CornFlowerBlue" />
    <br />

<?php

 $file = "test.txt";
 echo "<h3 style=color:Red>";
  echo "file last change (test.txt) : ";
  echo  date("F d Y H:i:s", filectime($file));
 echo "</h3>";
?>
</body>
</html>




php fileatime() function - how to get file last access time in php

php fileatime() function - how to get file last access time in php


fileatimeFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php fileatime() function - how to get file last access time in php</title>
</head>

<body>
    <h2 style="color:Crimson; font-style:italic">php fileatime() function example:<br /> how to get file last access time</h2>
    <hr width="375" align="left" color="Orange" />
    <br />

<?php

 $file = "test.txt";
 echo "<h3 style=color:Green>";
  echo "file last access (test.txt) : ";
  echo  date("F d Y H:i:s", fileatime($file));
 echo "</h3>";
?>
</body>
</html>




php file_put_contents() function - how to append a string to a file in php

php file_put_contents() function - how to append a string to a file in php


file_put_contentsFunctionAppend.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php file_put_contents() function - how to append a string to a file in php</title>
</head>

<body>
    <h2 style="color:Crimson; font-style:italic">php file_put_contents() function example:<br /> how to append a string to a file</h2>
    <hr width="375" align="left" color="Orange" />
    <br />

<?php

 $file = "testappend.txt";
 echo  file_put_contents($file," hello! ",FILE_APPEND);
 
?>
</body>
</html>




php file_put_contents() function - how to write a string to a file in php

php file_put_contents() function - how to write a string to a file in php


file_put_contentsFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>php file_put_contents() function - how to write a string to a file in php</title>
</head>

<body>
    <h2 style="color:SeaGreen; font-style:italic">php file_put_contents() function example:<br /> how to write a string to a file</h2>
    <hr width="375" align="left" color="Red" />
    <br />

<?php

 $file = "testputcontent.txt";
 echo  file_put_contents($file," hello! this is a string");
 
?>
</body>
</html>