File Manager / wp-content Search Upload New Item Settings File "db5.php" Full path: /home1/epichome/public_html/wp-content/db5.php File size: 60.67 B (60.67 KB bytes) MIME-type: text/x-php Charset: utf-8 Download Open Edit Advanced Editor Back
<?php
namespace NinjaForms\Includes\Admin\Processes;
/**
* Deletes a file given file path
*
*
*/
class DeleteBatchFile
{
/**
* Delete a file, given a filepath
*
* @param string $filePath
* @return string Result of the attempt to delete file
*/
public function delete(string $filePath): string
{
$return = __('File could not be found for deletion', 'ninja-forms');
$dir = wp_get_upload_dir();
$fileinfo = pathinfo($filePath);
$allowed_dir = $dir['basedir'] . '/ninja-forms-tmp' === $fileinfo['dirname'];
if(!$allowed_dir) {
$return = __('Permission denied to delete a file in that directory.', 'ninja-forms');
} else if (\file_exists($filePath)) {
\unlink($filePath);
$return = __('File was deleted', 'ninja-forms');
if (\file_exists($filePath)) {
// couldn't delete file for some reason
$return = __('File could not be deleted', 'ninja-forms');
}
}
return $return;
}
}
