Share & grow the world's code base!

Delve into a community where programmers unite to discover code snippets, exchange skills, and enhance their programming proficiency. With abundant resources and a supportive community, you'll find everything essential for your growth and success.

1 snippets
  • Removing all files from a folder using PHP

    <?php 
    
    $folderPath = "/tmp/test-folder"; 
    
    // List of files inside the folder 
    $files = glob($folderPath.'/*'); 
     
    foreach($files as $file) { 
    	if(is_file($file)) 
    		// Delete the given file 
    		unlink($file); 
    } 
    
    echo "Files deleted";
    
    // php main.php
    // Files deleted

    PHP program to delete all files from a specified folder.