117-a readfile — read file saved on server
This is testing text.The new text.Another new text.51

This is testing text.The new text.Another new text.51

File doest not exist

117-b copy — create a file on server
This is testing text.The new text.Another new text.51
117-c rename — rename the file
File doest not exist


117-d unlink — delete the file
File doest not exist


117-e mkdir — create a folder
Folder already exist

117-f rmdir — delete a folder

118-g filesize — data in bytes in the file (total characters)
filesize = 51
filetype = file
realpath = /home/u431596507/domains/rajats.in/public_html/allnew/allCodeFiles/phpcode/newfile.txt
 pathinfo = Array
(
    [dirname] => .
    [basename] => newfile.txt
    [extension] => txt
    [filename] => newfile
)
 pathinfo with full path = Array
(
    [dirname] => /home/u431596507/domains/rajats.in/public_html/allnew/allCodeFiles/phpcode
    [basename] => newfile.txt
    [extension] => txt
    [filename] => newfile
)
/home/u431596507/domains/rajats.in/public_html/allnew/allCodeFiles/phpcode
newfile.txt
txt
newfile
basename = newfile.txt
basename, with extensions hide = newfile
dirname = /home/u431596507/domains/rajats.in/public_html/allnew/allCodeFiles/phpcode
dirname with parameters = /home/u431596507/domains/rajats.in/public_html/allnew/allCodeFiles
<?php /*-------117-a readfile — read file saved on server------- */ echo "</br><h7 class='myheading'>117-a readfile — read file saved on server</h7></br>"; echo readfile("readme.txt")."<br><br>"; // using direct file name $var1 = readfile("readme.txt"); // usign variable echo $var1 . "<br><br>"; $file1 = "readme1.txt"; if(file_exists($file1)){ /* using file_exists function */ echo readfile("readme.txt"); }else{ echo "File doest not exist". "<br>"; } /*-------117-b copy — create a file on server------- */ echo "</br><h7 class='myheading'>117-b copy — create a file on server</h7></br>"; $file2 = "readme.txt"; if(file_exists($file2)){ echo readfile("readme.txt"); copy($file2,"newfile.txt"); /* copy (oldname,newname) */ }else{ echo "File doest not exist" . "<br>"; } /*-------117-c rename — rename the file ------- */ echo "</br><h7 class='myheading'>117-c rename — rename the file </h7></br>"; $file3 = "rajat.txt"; if(file_exists($file3)){ echo "file renamed" . "<br>"; rename("rajat.txt","renamed_rajat.txt"); /* old_name, new_name */ }else{ echo "File doest not exist" . "<br><br>"; } /*-------117-d unlink — delete the file ------- */ echo "</br><h7 class='myheading'>117-d unlink — delete the file</h7></br>"; $file4 = "renamed_rajat.txt"; if(file_exists($file4)){ unlink("renamed_rajat.txt"); /* delete the file , can use delete function also*/ }else{ echo "File doest not exist" . "<br><br>"; } /*-------117-e mkdir — create a folder ------- */ echo "</br><h7 class='myheading'>117-e mkdir — create a folder</h7></br>"; mkdir("rajt"); if(!file_exists("rajt")){ /* using conditions check before making the folder */ mkdir("rajt"); }else{ echo "Folder already exist". "<br>"; } /*-------117-f rmdir — delete a folder (access denied) ------- */ echo "</br><h7 class='myheading'>117-f rmdir — delete a folder</h7></br>"; if(file_exists("rajt")){ /* using conditions check before making the folder */ rmdir("rajt"); }else{ echo "folder not exist". "<br>"; } /*-------117-g filesize, filetype, realpath, pathinfo, basename ------- */ echo "</br><h7 class='myheading'>118-g filesize — data in bytes in the file (total characters)</h7></br>"; $file5 = "newfile.txt"; echo "filesize = ".filesize($file5) . "<br>"; // data in bytes (total characters) echo "filetype = ".filetype($file5) . "<br>"; //---- Return type of passing file(file or folder etc.) echo "realpath = ".realpath($file5) . "<br>"; //--- Get the full path of the file echo "<pre> pathinfo = "; print_r(pathinfo($file5)); //--- passing only file name , return array , same as realpath echo "</pre>"; echo "<pre> pathinfo with full path = "; print_r(pathinfo(realpath($file5))); //--- passing full path echo "</pre>"; print_r(pathinfo(realpath($file5),PATHINFO_DIRNAME)); //------- only dirname echo"<br>"; print_r(pathinfo(realpath($file5),PATHINFO_BASENAME)); //------ only basename echo"<br>"; print_r(pathinfo(realpath($file5),PATHINFO_EXTENSION)); //------ only extension echo"<br>"; print_r(pathinfo(realpath($file5),PATHINFO_FILENAME)); //------ only filename $path = realpath($file5); echo "<br>basename = ".basename($path); //Show filename using function = basename echo "<br>basename, with extensions hide = ".basename($path,".txt"); //Show filename, but cut off file extension need to mentioned like ".php" txt html echo "<br>dirname = ".dirname($path); //------ Return the path of the parent directory: echo "<br>dirname with parameters = ".dirname($path,2) . "<br>"; // return but hide one level directry ?>