本文整理汇总了PHP中wp_unique_filename函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_unique_filename函数的具体用法?PHP wp_unique_filename怎么用?PHP wp_unique_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_unique_filename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public function parse()
{
$tmpname = wp_unique_filename($this->targetDir, str_replace("sql", "xml", basename($this->_filename)));
$this->xml_path = $this->targetDir . '/' . url_title($tmpname);
$this->toXML();
return $this->xml_path;
}
示例2: ajax_change_slide_image
/**
* Change the slide image.
*
* This creates a copy of the selected (new) image and assigns the copy to our existing media file/slide.
*/
public function ajax_change_slide_image()
{
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'metaslider_changeslide')) {
wp_die(json_encode(array('status' => 'fail', 'msg' => __("Security check failed. Refresh page and try again.", "ml-slider"))));
}
$slide_from = absint($_POST['slide_from']);
$slide_to = absint($_POST['slide_to']);
// find the paths for the image we want to change to
// Absolute path
$abs_path = get_attached_file($slide_to);
$abs_path_parts = pathinfo($abs_path);
$abs_file_directory = $abs_path_parts['dirname'];
// Relative path
$rel_path = get_post_meta($slide_to, '_wp_attached_file', true);
$rel_path_parts = pathinfo($rel_path);
$rel_file_directory = $rel_path_parts['dirname'];
// old file name
$file_name = $abs_path_parts['basename'];
// new file name
$dest_file_name = wp_unique_filename($abs_file_directory, $file_name);
// generate absolute and relative paths for the new file name
$dest_abs_path = trailingslashit($abs_file_directory) . $dest_file_name;
$dest_rel_path = trailingslashit($rel_file_directory) . $dest_file_name;
// make a copy of the image
if (@copy($abs_path, $dest_abs_path)) {
// update the path on our slide
update_post_meta($slide_from, '_wp_attached_file', $dest_rel_path);
wp_update_attachment_metadata($slide_from, wp_generate_attachment_metadata($slide_from, $dest_abs_path));
update_attached_file($slide_from, $dest_rel_path);
wp_die(json_encode(array('status' => 'success')));
}
wp_die(json_encode(array('status' => 'fail', 'msg' => __("File copy failed. Please check upload directory permissions.", "ml-slider"))));
}
示例3: output
public function output()
{
$attachments = array();
if ($this->query->have_posts()) {
while ($this->query->have_posts()) {
$this->query->the_post();
global $post;
$invoice = WC_Germanized_Pro()->invoice_factory->get_invoice($post);
if ($invoice->has_attachment()) {
$attachments[$invoice->id] = array('path' => $invoice->get_pdf_path(), 'filename' => $invoice->get_filename());
}
}
}
if (!empty($attachments)) {
$upload_dir = WC_germanized_pro()->get_upload_dir();
$this->filename = wp_unique_filename($upload_dir['path'], $this->filename);
$this->filepath = trailingslashit($upload_dir['path']) . $this->filename;
$zip = new ZipArchive();
$zip->open($this->filepath, ZipArchive::CREATE);
foreach ($attachments as $attachment) {
$zip->addFile($attachment['path'], $attachment['filename']);
}
$zip->close();
header('Content-Length: ' . filesize($this->filepath));
readfile($this->filepath);
}
}
示例4: get_temporary_file_path
private function get_temporary_file_path($filename)
{
$uploads_dir = $this->settings->get_runtime_option('awpcp-uploads-dir');
$tempory_dir_path = implode(DIRECTORY_SEPARATOR, array($uploads_dir, 'tmp'));
$pathinfo = awpcp_utf8_pathinfo($filename);
$new_name = wp_hash($pathinfo['basename']) . '.' . $pathinfo['extension'];
$unique_filename = wp_unique_filename($tempory_dir_path, $new_name);
return $tempory_dir_path . DIRECTORY_SEPARATOR . $unique_filename;
}
示例5: awpcp_upload_image_file
/**
* @param $file A $_FILES item
*/
function awpcp_upload_image_file($directory, $filename, $tmpname, $min_size, $max_size, $min_width, $min_height, $uploaded = true)
{
$filename = sanitize_file_name($filename);
$newname = wp_unique_filename($directory, $filename);
$newpath = trailingslashit($directory) . $newname;
if (!file_exists($tmpname)) {
return sprintf(__('The specified image file does not exists: %s.', 'AWPCP'), $filename);
}
$ext = strtolower(awpcp_get_file_extension($filename));
$imginfo = getimagesize($tmpname);
$size = filesize($tmpname);
$allowed_extensions = array('gif', 'jpg', 'jpeg', 'png');
if (empty($filename)) {
return __('No file was selected.', 'AWPCP');
}
if ($uploaded && !is_uploaded_file($tmpname)) {
return __('Unknown error encountered while uploading the image.', 'AWPCP');
}
if (empty($size) || $size <= 0) {
$message = "There was an error trying to find out the file size of the image %s.";
return __(sprintf($message, $filename), 'AWPCP');
}
if (!in_array($ext, $allowed_extensions)) {
return sprintf(__('The file %s has an invalid extension and was rejected.', 'AWPCP'), $filename);
} elseif ($size < $min_size) {
$message = __('The size of %1$s was too small. The file was not uploaded. File size must be greater than %2$d bytes.', 'AWPCP');
return sprintf($message, $filename, $min_size);
} elseif ($size > $max_size) {
$message = __('The file %s was larger than the maximum allowed file size of %s bytes. The file was not uploaded.', 'AWPCP');
return sprintf($message, $filename, $max_size);
} elseif (!isset($imginfo[0]) && !isset($imginfo[1])) {
return sprintf(__('The file %s does not appear to be a valid image file.', 'AWPCP'), $filename);
} elseif ($imginfo[0] < $min_width) {
$message = __('The image %s did not meet the minimum width of %s pixels. The file was not uploaded.', 'AWPCP');
return sprintf($message, $filename, $min_width);
} elseif ($imginfo[1] < $min_height) {
$message = __('The image %s did not meet the minimum height of %s pixels. The file was not uploaded.', 'AWPCP');
return sprintf($message, $filename, $min_height);
}
if ($uploaded && !@move_uploaded_file($tmpname, $newpath)) {
$message = __('The file %s could not be moved to the destination directory.', 'AWPCP');
return sprintf($message, $filename);
} else {
if (!$uploaded && !@copy($tmpname, $newpath)) {
$message = __('The file %s could not be moved to the destination directory.', 'AWPCP');
return sprintf($message, $filename);
}
}
if (!awpcp_create_image_versions($newname, $directory)) {
$message = __('Could not create resized versions of image %s.', 'AWPCP');
# TODO: unlink resized version, thumbnail and primary image
@unlink($newpath);
return sprintf($message, $filename);
}
@chmod($newpath, 0644);
return array('original' => $filename, 'filename' => $newname);
}
示例6: wp_all_import_get_gz
function wp_all_import_get_gz($filename, $use_include_path = 0, $targetDir = false)
{
$type = 'csv';
$uploads = wp_upload_dir();
$targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
$tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
$localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
$fp = @fopen($localPath, 'w');
$file = @gzopen($filename, 'rb', $use_include_path);
if ($file) {
$first_chunk = true;
while (!gzeof($file)) {
$chunk = gzread($file, 1024);
if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
$type = 'xml';
$first_chunk = false;
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
@fwrite($fp, $chunk);
}
gzclose($file);
} else {
$tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
$localGZpath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
$request = get_file_curl($filename, $localGZpath, false, true);
if (!is_wp_error($request)) {
$file = @gzopen($localGZpath, 'rb', $use_include_path);
if ($file) {
$first_chunk = true;
while (!gzeof($file)) {
$chunk = gzread($file, 1024);
if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
$type = 'xml';
$first_chunk = false;
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
@fwrite($fp, $chunk);
}
gzclose($file);
}
@unlink($localGZpath);
} else {
return $request;
}
}
@fclose($fp);
if (preg_match('%\\W(gz)$%i', basename($localPath))) {
if (@rename($localPath, str_replace('.gz', '.' . $type, $localPath))) {
$localPath = str_replace('.gz', '.' . $type, $localPath);
}
} else {
if (@rename($localPath, $localPath . '.' . $type)) {
$localPath = $localPath . '.' . $type;
}
}
return array('type' => $type, 'localPath' => $localPath);
}
示例7: getTempFile
/**
* Caller should handle removal of the temp file when finished.
*
* @param string $ext The extension to be given to the temp file.
*
* @return string A temp file with the given extension.
*/
public static function getTempFile($ext = 'png')
{
static $base = null;
static $tmp;
if (is_null($base)) {
$base = md5(time());
$tmp = untrailingslashit(get_temp_dir());
}
return $tmp . DIRECTORY_SEPARATOR . wp_unique_filename($tmp, $base . '.' . $ext);
}
示例8: hs_get_auto_post_photo_url
function hs_get_auto_post_photo_url($size = "")
{
$photo = wp_unique_filename(wp_upload_dir()["url"], $_FILES["image"]["name"][0]);
$photo = wp_upload_dir()["url"] . "/" . $photo;
if ($size == "small") {
$extension_position = strrpos($photo, ".");
$photo_extension = substr($photo, $extension_position);
$photo = substr($photo, 0, $extension_position) . "-150x150" . $photo_extension;
}
return $photo;
}
示例9: setTempPath
public static function setTempPath($sFilePath = '')
{
$_sDir = get_temp_dir();
$sFilePath = basename($sFilePath);
if (empty($sFilePath)) {
$sFilePath = time() . '.tmp';
}
$sFilePath = $_sDir . wp_unique_filename($_sDir, $sFilePath);
touch($sFilePath);
return $sFilePath;
}
示例10: get_uploaded_thumbnail_path
private function get_uploaded_thumbnail_path()
{
$thumbnail = $this->request->post('thumbnail');
if (!preg_match('/data:([^;]*);base64,(.*)/', $thumbnail, $matches)) {
throw new AWPCP_Exception(__('No thumbnail data found.', 'AWPCP'));
}
$uploads_dir = $this->settings->get_runtime_option('awpcp-uploads-dir');
$filename = wp_unique_filename($uploads_dir, 'uploaded-thumbnail.png');
$uploaded_thumbnail_path = $uploads_dir . DIRECTORY_SEPARATOR . $filename;
file_put_contents($uploaded_thumbnail_path, base64_decode($matches[2]));
return $uploaded_thumbnail_path;
}
示例11: rh_css_settings_saved
function rh_css_settings_saved($notused1, $notused2)
{
$css = apply_filters('filter_rh_css', '');
$upload_dir = wp_upload_dir();
if (isset($upload_dir['error']) && false == $upload_dir['error']) {
$filename = wp_unique_filename($upload_dir['path'], 'righthere_styles.css');
$save_filename = $upload_dir['path'] . "/" . $filename;
if (false !== file_put_contents($save_filename, $css)) {
$url = $upload_dir['url'] . "/" . $filename;
update_option('righthere_styles_url', $url);
}
}
}
示例12: create_submission
public function create_submission($data = null)
{
$settings = get_option('fwe_settings');
$form_id = $settings['hire_us_form_id'];
$upload_dir = WP_CONTENT_DIR . '/rfp-uploads';
$success_msg = array_key_exists('hire_us_success_message', $settings) ? $settings['hire_us_success_message'] : 'Thank you!';
$mime_type = $data[19];
if ($mime_type && !in_array($mime_type, $this->allowed_mime_types)) {
return new WP_Error('That file type is not allowed.');
}
$invalid_fields = $this->validate_submission($data);
if (!empty($invalid_fields)) {
return new WP_Error('The following required fields were invalid: ' . implode(', ', $invalid_fields));
}
// Make the uploads folder if it doesn't exist
if (!is_dir($upload_dir)) {
$mkdir_success = wp_mkdir_p($upload_dir);
if (!$mkdir_success) {
return new WP_Error('Could not create upload directory.');
}
}
// Save the RFP file data as a file on the server
if (!empty($data['rfp_file_data'])) {
$filename = wp_unique_filename($upload_dir, $data[20]);
$file_data = $this->get_binary_data($data['rfp_file_data']);
$upload_path = trailingslashit($upload_dir) . $filename;
$file_url = content_url('/rfp-uploads/' . $filename);
if (!file_put_contents($upload_path, $file_data)) {
return new WP_Error('Error saving RFP file.');
}
// Don't store base64 garbage in the database
unset($data['rfp_file_data']);
}
// Store the form responses in Gravity Forms
$data['form_id'] = $form_id;
$data['date_created'] = strftime('%Y-%m-%d %H:%M');
$data[21] = $file_url;
$entry_id = GFAPI::add_entry($data);
// Give the user back a sanitized version of their input for displaying on the Thank You message
$response_data = array_merge($data, array('status' => 'OK', 'entry_id' => $entry_id, 'message' => $success_msg));
unset($response_data[21]);
$response = new WP_JSON_Response();
$response->set_data($response_data);
return $response;
}
示例13: wpdmp_create_attachment_from_file
function wpdmp_create_attachment_from_file($filepath)
{
if (empty($filepath)) {
return 0;
}
global $current_user;
get_currentuserinfo();
$logged_in_user = $current_user->ID;
// load up a variable with the upload direcotry
$uploads = wp_upload_dir();
$file = array('name' => strtolower(pathinfo($filepath, PATHINFO_FILENAME) . "." . pathinfo($filepath, PATHINFO_EXTENSION)), 'tmp_name' => $filepath);
$filename = wp_unique_filename($uploads['path'], $file['name'], $unique_filename_callback);
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/{$filename}";
if (false === @copy($file['tmp_name'], $new_file)) {
if (0 === strpos($uploads['basedir'], ABSPATH)) {
$error_path = str_replace(ABSPATH, '', $uploads['basedir']) . $uploads['subdir'];
} else {
$error_path = basename($uploads['basedir']) . $uploads['subdir'];
}
return sprintf(__('The uploaded file could not be moved to %s.', 'wp-design-maps-and-places'), $error_path);
}
// Set correct file permissions
$stat = stat(dirname($new_file));
$perms = $stat['mode'] & 0666;
@chmod($new_file, $perms);
// Compute the URL
$url = $uploads['url'] . "/{$filename}";
// checks the file type and stores in in a variable
$wp_filetype = wp_check_filetype(basename($new_file), null);
// set up the array of arguments for "wp_insert_post();"
$attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($new_file)), 'post_content' => '', 'post_author' => $logged_in_user, 'post_status' => 'inherit', 'post_type' => 'attachment', 'guid' => $url);
// insert the attachment post type and get the ID
//$attachment_id = wp_insert_post( $attachment );
$attachment_id = wp_insert_attachment($attachment, $new_file);
// generate the attachment metadata
$attach_data = wp_generate_attachment_metadata($attachment_id, $new_file);
// update the attachment metadata
wp_update_attachment_metadata($attachment_id, $attach_data);
return $attachment_id;
}
示例14: create_media_attachment
public function create_media_attachment()
{
$image_name = basename($this->external_url);
$upload_dir = wp_upload_dir();
$image_data = $this->get_image_data($this->external_url);
$unique_file_name = wp_unique_filename($upload_dir['path'], $image_name);
$filename = basename($unique_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);
$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);
return $attach_id;
}
示例15: save
public function save()
{
Helpers::debug("Upload::save called");
if (!(($uploads = wp_upload_dir($this->time)) && false === $uploads['error'])) {
throw new \Exception($uploads['error']);
}
$this->name = $this->getProperName();
$filename = wp_unique_filename($uploads['path'], $this->name, NULL);
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/{$filename}";
if (false === @move_uploaded_file($this->tmp_name, $new_file)) {
throw new \Exception(sprintf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
}
$this->path = $new_file;
$this->stat = stat(dirname($new_file));
$this->perms = $this->stat['mode'] & 0666;
@chmod($new_file, $this->perms);
// Compute the URL
$this->url = $uploads['url'] . "/{$filename}";
if (is_multisite()) {
delete_transient('dirsize_cache');
}
Helpers::debug("Upload::save finished");
}