Revisions for "Use PHP to delete file types in a directory and its sub directories"

Use PHP to delete file types in a directory and its sub directories

I'm having my graphic design students upload files to a server. I want the following PHP code to also delete all .js and .php files in the newly created directories and any subdirectories.

<?php

$ds = DIRECTORY_SEPARATOR;
$storeFolder1 = '../../testserverOne/';
$storeFolder2 = '../../testserverTwo/';
$rand = substr(md5(time()),0,8);

if (!empty($_FILES)) {

    $tempFile = $_FILES['file']['tmp_name'];

    $targetPath1 = dirname( __FILE__ ) . $ds . $storeFolder1 . $ds;
    $targetPath2 = dirname( __FILE__ ) . $ds . $storeFolder2 . $ds;

    $fullPath1 = $storeFolder1.rtrim($_POST['path'], "/.");
    $fullPath2 = $storeFolder2.rtrim($_POST['path'], "/.");

    $folder1 = substr($fullPath1, 0, strrpos($fullPath1, "/"));
    $folder2 = substr($fullPath2, 0, strrpos($fullPath2, "/"));

    if (!is_dir($folder1)) {
        $old1 = umask(0);
        $old2 = umask(0);
        mkdir($folder1, 0777, true);
        mkdir($folder2, 0777, true);
        umask($old1);
        umask($old2);
    }

    if (move_uploaded_file($tempFile, $fullPath1)) {
        copy($fullPath1, $fullPath2);
        die('Uploaded');
    } else {
        die('Error');
    }

}

?>
Use PHP to delete file types in a directory and its sub directories
I'm having my graphic design students upload files to a server. I want the following PHP code to alsorecursively delete all .js and .php files in the newlyuploaded created directories and any subdirectories. Currently, the code only deletes the .js and .php files in the top-level directory, not in the subdirectories as well. ); } ); } array_map('unlink', glob($folder1."/*.js")); array_map('unlink', glob($folder1."/*.php")); if (move_uploaded_file($tempFile, $fullPath1)) { copy($fullPath1, $fullPath2); die('Uploaded'); } else { die('Error'); } } ?>
Use PHP to delete file types in a directory and its sub directories
I'm having my graphic design students upload files to a server. I want the following PHP code to recursively delete all .js and .php files in the uploaded directories and any subdirectories. Currently, the code only deletes the .js and .php files in the top-level directory, not in the subdirectories as well. OK, I wantactually got the following PHP code to recursivelywork deletemyself all .jswhile I was waiting for the bounty to be filled. So, instead, I'm now looking for someone to add the function of stripping out any code between `` and . `` tags inside of HTML files that get uploaded. php $ds = DIRECTORY_SEPARATOR; $storeFolder1 = '../../testserverOne/'; $storeFolder2 = '../../testserverTwo/'; $rand = substr(md5(time()),0,8); if (!empty($_FILES)) { $tempFile = $_FILES['file']['tmp_name']; $targetPath1 = dirname( __FILE__ ) . $ds . $storeFolder1 . $ds; $targetPath2 = dirname( __FILE__ ) . $ds . $storeFolder2 . $ds; $fullPath1 = $storeFolder1.rtrim($_POST['path'], "/."); $fullPath2 = $storeFolder2.rtrim($_POST['path'], "/."); $folder1 = substr($fullPath1, 0, strrpos($fullPath1, "/")); $folder2 = substr($fullPath2, 0, strrpos($fullPath2, "/")); if (!is_dir($folder1)) { $old1 = umask(0); $old2 = umask(0); mkdir($folder1, 0777, true); mkdir($folder2, 0777, true); umask($old1); umask($old2); } $directory1 = $storeFolder1; $iterator1 = new files in the uploaded directories and any subdirectories. Currently, the code only deletes the .js and .php files in the top-level directory, not in the subdirectories as well. RecursiveDirectoryIterator($_FILES)) { $directory1); $directoryIterator1 = new RecursiveIteratorIterator($iterator1); foreach ($directoryIterator1 as $file1) { $extension1 = $file1->getExtension(); if (!$file1->isDir() && $extension1 == 'php' || $extension1 == 'js') { unlink($file1->getPathname()); } } $directory2 = $storeFolder2; $iterator2 = new RecursiveDirectoryIterator($directory2); $directoryIterator2 = new RecursiveIteratorIterator($iterator2); foreach ($directoryIterator2 as $file2) { $extension2 = $file2->getExtension(); if (!$file2->isDir() && $extension2 == 'php' || $extension2 == 'js') { unlink($file2->getPathname()); } } //array_map('unlink', glob($folder1."/*.js")); //array_map('unlink', glob($folder1."/*.php")); if (move_uploaded_file($tempFile = $_FILES['file']['tmp_name']; $targetPath1 = dirname( __FILE__ ) . $ds . $storeFolder1 . $ds; $targetPath2 = dirname( __FILE__ ) . $ds . $storeFolder2 . $ds; $fullPath1 = $storeFolder1.rtrim($_POST['path'], "/."); $fullPath2 = $storeFolder2.rtrim($_POST['path'], "/."); $folder1 = substr($fullPath1, 0, strrpos($fullPath1, "/")); $folder2 = substr($fullPath2, 0, strrpos($fullPath2, "/")); if (!is_dir($folder1)) { $old1 = umask(0); $old2 = umask(0); mkdir($folder1, 0777, true); mkdir($folder2, 0777, true); umask($old1); umask($old2); } array_map('unlink', glob($folder1."/*.js")); array_map('unlink', glob($folder1."/*.php")); if (move_uploaded_file($tempFile, $fullPath1)) { copy($fullPath1, $fullPath2); die('Uploaded'); } else { die('Error'); } } ?>
Back to question