本文整理汇总了PHP中sanitize_file_name函数的典型用法代码示例。如果您正苦于以下问题:PHP sanitize_file_name函数的具体用法?PHP sanitize_file_name怎么用?PHP sanitize_file_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sanitize_file_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cimy_um_download_database
function cimy_um_download_database()
{
global $cum_upload_path;
if (!empty($_POST["cimy_um_filename"])) {
if (strpos($_SERVER['HTTP_REFERER'], admin_url('users.php?page=cimy_user_manager')) !== false) {
// not whom we are expecting? exit!
if (!check_admin_referer('cimy_um_download', 'cimy_um_downloadnonce')) {
return;
}
$cimy_um_filename = $_POST["cimy_um_filename"];
// sanitize the file name
$cimy_um_filename = sanitize_file_name($cimy_um_filename);
$cimy_um_fullpath_file = $cum_upload_path . $cimy_um_filename;
// does not exist? exit!
if (!is_file($cimy_um_fullpath_file)) {
return;
}
header("Pragma: ");
// Leave blank for issues with IE
header("Expires: 0");
header('Vary: User-Agent');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: text/csv");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=\"" . esc_html($cimy_um_filename) . "\";");
// cannot use esc_url any more because prepends 'http' (doh)
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($cimy_um_fullpath_file));
readfile($cimy_um_fullpath_file);
exit;
}
}
}
示例2: pleiofile_add_folder_to_zip
function pleiofile_add_folder_to_zip(ZipArchive &$zip_archive, ElggObject $folder, $folder_path = "")
{
if (!empty($zip_archive) && !empty($folder) && elgg_instanceof($folder, "object", "folder")) {
$folder_title = elgg_get_friendly_title($folder->title);
$zip_archive->addEmptyDir($folder_path . $folder_title);
$folder_path .= $folder_title . DIRECTORY_SEPARATOR;
$file_options = array("type" => "object", "subtype" => "file", "limit" => false, "relationship" => "folder_of", "relationship_guid" => $folder->getGUID());
// add files from this folder to the zip
if ($files = elgg_get_entities_from_relationship($file_options)) {
foreach ($files as $file) {
// check if the file exists
if ($zip_archive->statName($folder_path . $file->originalfilename) === false) {
// doesn't exist, so add
$zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file->originalfilename));
} else {
// file name exists, so create a new one
$ext_pos = strrpos($file->originalfilename, ".");
$file_name = substr($file->originalfilename, 0, $ext_pos) . "_" . $file->getGUID() . substr($file->originalfilename, $ext_pos);
$zip_archive->addFile($file->getFilenameOnFilestore(), $folder_path . sanitize_file_name($file_name));
}
}
}
// check if there are subfolders
$folder_options = array("type" => "object", "subtype" => "folder", "limit" => false, "metadata_name_value_pairs" => array("parent_guid" => $folder->getGUID()));
if ($sub_folders = elgg_get_entities_from_metadata($folder_options)) {
foreach ($sub_folders as $sub_folder) {
pleiofile_add_folder_to_zip($zip_archive, $sub_folder, $folder_path);
}
}
}
}
示例3: handle_upload_prefilter
function handle_upload_prefilter($file)
{
// We must sanitize before dupe control...
$file['name'] = sanitize_file_name($file['name']);
$log = wpro()->debug->logblock('WPRO_Uploads::handle_upload_prefilter()');
if (wpro()->backends->is_backend_activated() && !$this->disableFileDupeControl) {
$upload = wp_upload_dir();
$name = $file['name'];
$path = trim($upload['url'], '/') . '/' . $name;
$counter = 0;
$exists = true;
while ($exists) {
$exists = apply_filters('wpro_backend_file_exists', null, $path);
if (is_null($exists)) {
// no wpro_backend_file_exists filter, or the filter returned null.
// use standard exists check (using http(s) request...)
$exists = wpro()->http->url_exists($path);
}
if ($exists) {
if (preg_match('/\\.([^\\.\\/]+)$/', $file['name'], $regs)) {
$ending = '.' . $regs[1];
$preending = substr($file['name'], 0, 0 - strlen($ending));
$name = $preending . '_' . $counter . $ending;
} else {
$name = $file['name'] . '_' . $counter;
}
$path = trim($upload['url'], '/') . '/' . $name;
$counter++;
}
}
$file['name'] = $name;
}
return $log->logreturn($file);
}
示例4: setImage
/**
* Set image
*
* @param string $keyImg
* Key from the image
* @param file $imgFile
* The image
* @throws Exception
* @return void|string
*/
protected function setImage($keyImg, $imgFile)
{
// If it's false or null we have to remove it from the server
if (!$imgFile || is_null($imgFile)) {
return $this->removeImage($keyImg);
}
if (strpos($imgFile['name'], '.php') !== false) {
throw new Exception('For security reasons, the extension ".php" cannot be in your file name.');
}
$avatar = wp_handle_upload($_FILES[$keyImg], array('mimes' => array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png'), 'test_form' => false, 'unique_filename_callback' => function ($dir, $name, $ext) use($keyImg) {
$name = $base_name = sanitize_file_name($this->user_login . '_' . $keyImg);
$number = 1;
while (file_exists($dir . "/{$name}{$ext}")) {
$name = $base_name . '_' . $number;
$number++;
}
return $name . $ext;
}));
// Remove the last image
$this->removeImage($keyImg);
$metaValue = array();
$url_or_media_id = $avatar['url'];
// Set the new image
if (is_int($url_or_media_id)) {
$metaValue['media_id'] = $url_or_media_id;
$url_or_media_id = wp_get_attachment_url($url_or_media_id);
}
$metaValue['full'] = $url_or_media_id;
return update_user_meta($this->ID, $keyImg, $metaValue);
}
示例5: handle_download_data
/**
* Listen for diagnostic log requests and render it
*/
public function handle_download_data()
{
global $typenow;
if (!isset($typenow) || INSTAGRATEPRO_POST_TYPE !== $typenow) {
return;
}
$download = filter_input(INPUT_GET, 'download');
if (!isset($download) || 'data' !== $download) {
return;
}
$nonce = filter_input(INPUT_GET, 'nonce');
if (!isset($nonce) || !wp_verify_nonce($nonce, 'install-data')) {
return;
}
$log = $this->get_install_body();
$url = parse_url(home_url());
$host = sanitize_file_name($url['host']);
$filename = sprintf('%s-intagrate-install-data-%s.txt', $host, date('YmdHis'));
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . strlen($log));
header('Content-Disposition: attachment; filename=' . $filename);
echo $log;
exit;
}
示例6: wp_rp_upload_attachment
/**
* Cron - Thumbnail extraction
*/
function wp_rp_upload_attachment($url, $post_id)
{
/* Parts copied from wp-admin/includes/media.php:media_sideload_image */
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/media.php';
include_once ABSPATH . 'wp-admin/includes/image.php';
$tmp = download_url($url);
preg_match('/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i', $url, $matches);
$file_array['name'] = sanitize_file_name(urldecode(basename($matches[0])));
$file_array['tmp_name'] = $tmp;
if (is_wp_error($tmp)) {
@unlink($file_array['tmp_name']);
return false;
}
$post_data = array('guid' => $url, 'post_title' => 'rp_' . $file_array['name']);
$attachment_id = media_handle_sideload($file_array, $post_id, null, $post_data);
if (is_wp_error($attachment_id)) {
@unlink($file_array['tmp_name']);
return false;
}
$attach_data = wp_get_attachment_metadata($attachment_id);
$platform_options = wp_rp_get_platform_options();
$min_width = $platform_options['custom_size_thumbnail_enabled'] ? WP_RP_CUSTOM_THUMBNAILS_WIDTH : WP_RP_THUMBNAILS_WIDTH;
$min_height = $platform_options['custom_size_thumbnail_enabled'] ? WP_RP_CUSTOM_THUMBNAILS_HEIGHT : WP_RP_THUMBNAILS_HEIGHT;
if (!$attach_data || $attach_data['width'] < $min_width || $attach_data['height'] < $min_height) {
wp_delete_attachment($attachment_id);
return false;
}
return $attachment_id;
}
示例7: validation
/**
* Validates whether the gallery can be saved
*/
function validation()
{
// If a title is present, we can auto-populate some other properties
if (isset($this->object->title)) {
// If no name is present, use the title to generate one
if (!isset($this->object->name)) {
$this->object->name = sanitize_file_name(sanitize_title($this->object->title));
$this->object->name = apply_filters('ngg_gallery_name', $this->object->name);
}
// If no slug is set, use the title to generate one
if (!isset($this->object->slug)) {
$this->object->slug = nggdb::get_unique_slug(sanitize_title($this->object->title), 'gallery');
}
}
// Set what will be the path to the gallery
if (empty($this->object->path)) {
$storage = $this->object->get_registry()->get_utility('I_Gallery_Storage');
$this->object->path = $storage->get_upload_relpath($this->object);
unset($storage);
}
$this->object->validates_presence_of('title');
$this->object->validates_presence_of('name');
$this->object->validates_uniqueness_of('slug');
$this->object->validates_numericality_of('author');
return $this->object->is_valid();
}
示例8: do_open
/**
* Display book in a custom format.
*/
function do_open()
{
if (!array_key_exists('open', $GLOBALS['wp_query']->query_vars)) {
// Don't do anything and return
return;
}
$action = get_query_var('open');
if ('download' == $action) {
// Download
if (!empty($_GET['filename']) && !empty($_GET['type'])) {
$filename = sanitize_file_name($_GET['filename']);
switch ($_GET['type']) {
case 'xhtml':
$ext = 'html';
break;
case 'wxr':
$ext = 'xml';
break;
case 'epub3':
$ext = '_3.epub';
break;
default:
$ext = $_GET['type'];
break;
}
$filename = $filename . '.' . $ext;
download_open_export_file($filename);
}
}
wp_die(__('Error: Unknown export format.', 'pressbooks-textbook'));
}
示例9: add_image
static function add_image($image_url)
{
if (empty($image_url)) {
return FALSE;
}
// Add Featured Image to Post
$upload_dir = wp_upload_dir();
// Set upload folder
$image_data = file_get_contents($image_url);
// Get image data
$filename = basename($image_url);
// Create image file name
// Check folder permission and define file location
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents($file, $image_data);
// Check image file type
$wp_filetype = wp_check_filetype($filename, NULL);
// Set attachment data
$attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit');
// Create the attachment
$attach_id = wp_insert_attachment($attachment, $file);
// Include image.php
require_once ABSPATH . 'wp-admin/includes/image.php';
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata($attach_id, $file);
// Assign metadata to attachment
wp_update_attachment_metadata($attach_id, $attach_data);
return $attach_id;
}
示例10: uploadFile
static function uploadFile($file_url, $path, $file_name)
{
$file_name = sanitize_file_name($file_name);
$full_file_name = $path . DIRECTORY_SEPARATOR . $file_name;
//Local name
$response = wp_remote_get($file_url, array('timeout' => 10 * 60 * 60, 'stream' => true, 'filename' => $full_file_name));
if (is_wp_error($response)) {
@unlink($full_file_name);
throw new Exception('Error: ' . $response->get_error_message());
}
if (200 != wp_remote_retrieve_response_code($response)) {
@unlink($full_file_name);
throw new Exception('Error 404: ' . trim(wp_remote_retrieve_response_message($response)));
}
if (substr($file_name, -12) == ".phpfile.txt") {
$new_file_name = substr($file_name, 0, -12) . ".php";
$new_file_name = $path . DIRECTORY_SEPARATOR . $new_file_name;
$moved = @rename($full_file_name, $new_file_name);
if ($moved) {
return array('path' => $new_file_name);
} else {
@unlink($full_file_name);
throw new Exception('Error: Copy file.');
}
}
return array('path' => $full_file_name);
}
示例11: grav_submit_to_s3
function grav_submit_to_s3($entry, $form)
{
// no file? no problem.
if (empty($entry[GFORM_UPLOAD_FIELD_ID])) {
return;
}
$gfs3 = new S3(awsAccessKey, awsSecretKey);
// url of uploaded file
$file_url = $entry[GFORM_UPLOAD_FIELD_ID];
// filename of uploaded file
$file_name = $_FILES['input_' . GFORM_UPLOAD_FIELD_ID]['name'];
// ensure bucket is there
$gfs3->putBucket(BUCKET_NAME, S3::ACL_AUTHENTICATED_READ);
// clean up filename, split into parts
$url_parts = parse_url($file_url);
$full_path = $_SERVER['DOCUMENT_ROOT'] . substr($url_parts['path'], 1);
if (is_dir($file_name)) {
$file_name = basename($file_name);
}
// this is the full path to the file on S3
$filename_to_s3 = UPLOAD_PATH . sanitize_file_name($file_name);
if ($gfs3->putObjectFile($full_path, BUCKET_NAME, $filename_to_s3, S3::ACL_PUBLIC_READ)) {
return true;
// upload success
} else {
wp_die('It looks like something went wrong while uploading your file. Please try again in a few moments.');
}
}
示例12: sp_AdminLinksTag
function sp_AdminLinksTag($args = '', $label = '', $toolTip = '')
{
global $spThisUser, $spDevice;
# bail if not admin or moderator
if (!$spThisUser->admin) {
return;
}
# is this admin showing the admin bar?
if (!isset($spThisUser->sfadminbar) || $spThisUser->sfadminbar == false) {
return;
}
$defs = array('tagId' => 'spAdminLinks', 'tagClass' => 'spAdminLinks', 'icon' => 'sp_AdminLinks.png', 'iconClass' => 'spAdminLinks');
$a = wp_parse_args($args, $defs);
$a = apply_filters('sph_AdminLinks_args', $a);
extract($a, EXTR_SKIP);
$p = $spDevice == 'mobile' && current_theme_supports('sp-theme-responsive') ? SPABIMAGESMOB : SPABIMAGES;
# sanitize before use
$tagId = esc_attr($tagId);
$tagClass = esc_attr($tagClass);
$iconClass = esc_attr($iconClass);
$icon = sp_paint_icon($iconClass, $p, sanitize_file_name($icon));
$toolTip = esc_attr($toolTip);
$label = sp_filter_title_display($label);
$site = SFHOMEURL . "index.php?sp_ahah=admin-bar-links&sfnonce=" . wp_create_nonce('forum-ahah') . "&action=manage";
$out = "<a class='{$tagClass}' id='{$tagId}' title='{$toolTip}' rel='nofollow' href='javascript:void(null)' onclick='spjDialogAjax(this, \"{$site}\", \"{$label}\", 250, 0, 0);'>";
if (!empty($icon)) {
$out .= $icon;
}
if (!empty($label)) {
$out .= $label;
}
$out .= "</a>\n";
$out = apply_filters('sph_AdminLinks', $out, $a);
echo $out;
}
示例13: remove_accents
/**
* Removes all accents from string
* @param string $filename - any filename with absolute path
* @param bool $sanitize - Sanitized all special characters as well?
*/
public static function remove_accents($filename, $sanitize = true)
{
# Get path and basename
$file_info = pathinfo($filename);
$filename = $file_info['basename'];
# If available remove all NFD characters before doing anything else
if (class_exists('Normalizer')) {
$filename = Normalizer::normalize($filename, Normalizer::FORM_C);
}
# Removes accents using wordpress function
$filename = remove_accents($filename);
if ($sanitize) {
# Sanitize special characters for files so that they work in urls
$filename = sanitize_file_name($filename);
}
# And then just remove anything fancy like ¼ and ™
$filename = self::remove_non_ascii_characters($filename);
# If this was full path return it like it was before
# pathinfo returns . for only filenames
if ($file_info['dirname'] != '.') {
$filename = $file_info['dirname'] . '/' . $filename;
}
# Return full path
return $filename;
}
示例14: programmatically_create_post
function programmatically_create_post()
{
$url = 'http://widgets.pinterest.com/v3/pidgets/boards/bradleyblose/my-stuff/pins/';
$json_O = json_decode(file_get_contents($url), true);
$id = $json_O['data']['pins'][0]['id'];
$titlelink = 'https://www.pinterest.com/pin/' . $id . '/';
$title = get_title($titlelink);
var_dump($title);
$original = $json_O['data']['pins'][0]['images']['237x']['url'];
$image_url = preg_replace('/237x/', '736x', $original);
$description = $json_O['data']['pins'][0]['description'];
// Initialize the page ID to -1. This indicates no action has been taken.
$post_id = -1;
// Setup the author, slug, and title for the post
$author_id = 1;
$mytitle = get_page_by_title($title, OBJECT, 'post');
var_dump($mytitle);
// If the page doesn't already exist, then create it
if (NULL == get_page_by_title($title, OBJECT, 'post')) {
// Set the post ID so that we know the post was created successfully
$post_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $author_id, 'post_name' => $title, 'post_title' => $title, 'post_content' => $description, 'post_status' => 'publish', 'post_type' => 'post'));
//upload featured image
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $filename;
$path = $upload_dir['path'] . '/';
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
$path = $upload_dir['basedir'] . '/';
}
file_put_contents($file, $image_data);
//edit featured image to correct specs to fit theme
$pngfilename = $filename . '.png';
$targetThumb = $path . '/' . $pngfilename;
$img = new Imagick($file);
$img->scaleImage(250, 250, true);
$img->setImageBackgroundColor('None');
$w = $img->getImageWidth();
$h = $img->getImageHeight();
$img->extentImage(250, 250, ($w - 250) / 2, ($h - 250) / 2);
$img->writeImage($targetThumb);
unlink($file);
//Attach featured image
$wp_filetype = wp_check_filetype($pngfilename, null);
$attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($pngfilename), 'post_content' => '', 'post_status' => 'inherit');
$attach_id = wp_insert_attachment($attachment, $targetThumb, $post_id);
require_once ABSPATH . 'wp-admin/includes/image.php';
$attach_data = wp_generate_attachment_metadata($attach_id, $targetThumb);
wp_update_attachment_metadata($attach_id, $attach_data);
set_post_thumbnail($post_id, $attach_id);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
}
// end if
}
示例15: __construct
function __construct()
{
self::$instance =& $this;
/* GETS INFORMATIONS FROM STYLE.CSS */
// get themedata version wp 3.4+
if (function_exists('wp_get_theme')) {
//get WP_Theme object of customizr
$tc_theme = wp_get_theme();
//Get infos from parent theme if using a child theme
$tc_theme = $tc_theme->parent() ? $tc_theme->parent() : $tc_theme;
$tc_base_data['prefix'] = $tc_base_data['title'] = $tc_theme->name;
$tc_base_data['version'] = $tc_theme->version;
$tc_base_data['authoruri'] = $tc_theme->{'Author URI'};
} else {
$tc_base_data = call_user_func('get_' . 'theme_data', get_stylesheet_directory() . '/style.css');
$tc_base_data['prefix'] = $tc_base_data['title'];
}
self::$theme_name = sanitize_file_name(strtolower($tc_base_data['title']));
//CUSTOMIZR_VER is the Version
if (!defined('CUSTOMIZR_VER')) {
define('CUSTOMIZR_VER', $tc_base_data['version']);
}
//TC_BASE is the root server path of the parent theme
if (!defined('TC_BASE')) {
define('TC_BASE', get_template_directory() . '/');
}
//TC_BASE_CHILD is the root server path of the child theme
if (!defined('TC_BASE_CHILD')) {
define('TC_BASE_CHILD', get_stylesheet_directory() . '/');
}
//TC_BASE_URL http url of the loaded parent theme
if (!defined('TC_BASE_URL')) {
define('TC_BASE_URL', get_template_directory_uri() . '/');
}
//TC_BASE_URL_CHILD http url of the loaded child theme
if (!defined('TC_BASE_URL_CHILD')) {
define('TC_BASE_URL_CHILD', get_stylesheet_directory_uri() . '/');
}
//THEMENAME contains the Name of the currently loaded theme
if (!defined('THEMENAME')) {
define('THEMENAME', $tc_base_data['title']);
}
//TC_WEBSITE is the home website of Customizr
if (!defined('TC_WEBSITE')) {
define('TC_WEBSITE', $tc_base_data['authoruri']);
}
//this is the structure of the Customizr code : groups => ('path' , 'class_suffix')
$this->tc_core = apply_filters('tc_core', array('fire' => array(array('inc', 'init'), array('inc', 'utils_settings_map'), array('inc', 'utils'), array('inc', 'resources'), array('inc', 'widgets'), array('inc/admin', 'admin_init'), array('inc/admin', 'admin_page')), 'header' => array(array('inc/parts', 'header_main'), array('inc/parts', 'menu'), array('inc/parts', 'nav_walker')), 'content' => array(array('inc/parts', '404'), array('inc/parts', 'attachment'), array('inc/parts', 'breadcrumb'), array('inc/parts', 'comments'), array('inc/parts', 'featured_pages'), array('inc/parts', 'gallery'), array('inc/parts', 'headings'), array('inc/parts', 'no_results'), array('inc/parts', 'page'), array('inc/parts', 'post_thumbnails'), array('inc/parts', 'post'), array('inc/parts', 'post_list'), array('inc/parts', 'post_metas'), array('inc/parts', 'post_navigation'), array('inc/parts', 'sidebar'), array('inc/parts', 'slider')), 'footer' => array(array('inc/parts', 'footer_main')), 'addons' => apply_filters('tc_addons_classes', array())));
//end of filters
//check the context
if (file_exists(sprintf('%sinc/init-pro.php', TC_BASE)) && 'customizr-pro' == self::$theme_name) {
require_once sprintf('%sinc/init-pro.php', TC_BASE);
self::$tc_option_group = 'tc_theme_options';
} else {
self::$tc_option_group = 'tc_theme_options';
}
//theme class groups instanciation
$this->tc__($this->tc_core);
}