Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



wp_delete_file_from_directory ›

Od4.9.7
Przestarzałyn/a
wp_delete_file_from_directory ( $file, $directory )
Parametry: (2)
  • (string) $file Absolute path to the file to delete.
    Wymagane: Tak
  • (string) $directory Absolute path to a directory.
    Wymagane: Tak
Powrót:
  • (bool) True on success, false on failure.
Zdefiniowane na:
Codex:

Deletes a file if its path is within the given directory.



Źródło

function wp_delete_file_from_directory( $file, $directory ) {
	if ( wp_is_stream( $file ) ) {
		$real_file      = $file;
		$real_directory = $directory;
	} else {
		$real_file      = realpath( wp_normalize_path( $file ) );
		$real_directory = realpath( wp_normalize_path( $directory ) );
	}

	if ( false !== $real_file ) {
		$real_file = wp_normalize_path( $real_file );
	}

	if ( false !== $real_directory ) {
		$real_directory = wp_normalize_path( $real_directory );
	}

	if ( false === $real_file || false === $real_directory || strpos( $real_file, trailingslashit( $real_directory ) ) !== 0 ) {
		return false;
	}

	wp_delete_file( $file );

	return true;
}