本文整理汇总了PHP中wp_unique_filename函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_unique_filename函数的具体用法?PHP wp_unique_filename怎么用?PHP wp_unique_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_unique_filename函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:rebeccayshen,项目名称:kitlist,代码行数:7,代码来源:XmlImportSQLParse.php
示例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"))));
}
开发者ID:WordPressArt,项目名称:conisia,代码行数:38,代码来源:metaslide.class.php
示例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);
}
}
开发者ID:radscheit,项目名称:unicorn,代码行数:27,代码来源:class-wc-gzdp-admin-invoice-export-attachments.php
示例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;
}
开发者ID:sabdev1,项目名称:ljcdevsab,代码行数:9,代码来源:class-file-uploader.php
示例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);
}
开发者ID:sabdev1,项目名称:ljcdevsab,代码行数:60,代码来源:upload_awpcp.php
示例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);
}
开发者ID:lizbur10,项目名称:js_finalproject,代码行数:57,代码来源:wp_all_import_get_gz.php
示例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);
}
开发者ID:WildCodeSchool,项目名称:projet-maison_ados_dreux,代码行数:17,代码来源:class-util.php
示例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;
}
开发者ID:honeysilvas,项目名称:Auto-post_Listing,代码行数:11,代码来源:listing.php
示例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;
}
开发者ID:jaime5x5,项目名称:seamless-donations,代码行数:11,代码来源:AdminPageFramework_WPUtility_File.php
示例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;
}
开发者ID:sabdev1,项目名称:ljcdevsab,代码行数:12,代码来源:class-upload-generated-thumbnail-ajax-handler.php
示例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);
}
}
}
开发者ID:kaydwithers,项目名称:crossfittanjongpagar,代码行数:13,代码来源:class.righthere_css_frontend.php
示例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;
}
开发者ID:RandJSC,项目名称:fourth-wall-wordpress,代码行数:45,代码来源:hire-us.php
示例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;
}
开发者ID:Wikipraca,项目名称:Wikipraca-WikiSquare,代码行数:41,代码来源:wpdmp-attach-file.php
示例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;
}
开发者ID:bermanco,项目名称:wordpress-image-download,代码行数:22,代码来源:WordpressImageDownload.php
示例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");
}
开发者ID:borisdiakur,项目名称:woocommerce-json-api,代码行数:24,代码来源:Upload.php
示例16: wp_upload_bits
/**
* Create a file in the upload folder with given content.
*
* If there is an error, then the key 'error' will exist with the error message.
* If success, then the key 'file' will have the unique file path, the 'url' key
* will have the link to the new file. and the 'error' key will be set to false.
*
* This function will not move an uploaded file to the upload folder. It will
* create a new file with the content in $bits parameter. If you move the upload
* file, read the content of the uploaded file, and then you can give the
* filename and content to this function, which will add it to the upload
* folder.
*
* The permissions will be set on the new file automatically by this function.
*
* @since 2.0.0
*
* @param string $name Filename.
* @param null|string $deprecated Never used. Set to null.
* @param mixed $bits File content
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
* @return array
*/
function wp_upload_bits($name, $deprecated, $bits, $time = null)
{
if (!empty($deprecated)) {
_deprecated_argument(__FUNCTION__, '2.0');
}
if (empty($name)) {
return array('error' => __('Empty filename'));
}
$wp_filetype = wp_check_filetype($name);
if (!$wp_filetype['ext'] && !current_user_can('unfiltered_upload')) {
return array('error' => __('Invalid file type'));
}
$upload = wp_upload_dir($time);
if ($upload['error'] !== false) {
return $upload;
}
/**
* Filter whether to treat the upload bits as an error.
*
* Passing a non-array to the filter will effectively short-circuit preparing
* the upload bits, returning that value instead.
*
* @since 3.0.0
*
* @param mixed $upload_bits_error An array of upload bits data, or a non-array error to return.
*/
$upload_bits_error = apply_filters('wp_upload_bits', array('name' => $name, 'bits' => $bits, 'time' => $time));
if (!is_array($upload_bits_error)) {
$upload['error'] = $upload_bits_error;
return $upload;
}
$filename = wp_unique_filename($upload['path'], $name);
$new_file = $upload['path'] . "/{$filename}";
if (!wp_mkdir_p(dirname($new_file))) {
if (0 === strpos($upload['basedir'], ABSPATH)) {
$error_path = str_replace(ABSPATH, '', $upload['basedir']) . $upload['subdir'];
} else {
$error_path = basename($upload['basedir']) . $upload['subdir'];
}
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $error_path);
return array('error' => $message);
}
$ifp = @fopen($new_file, 'wb');
if (!$ifp) {
return array('error' => sprintf(__('Could not write file %s'), $new_file));
}
@fwrite($ifp, $bits);
fclose($ifp);
clearstatcache();
// Set correct file permissions
$stat = @stat(dirname($new_file));
$perms = $stat['mode'] & 07777;
$perms = $perms & 0666;
@chmod($new_file, $perms);
clearstatcache();
// Compute the URL
$url = $upload['url'] . "/{$filename}";
/** This filter is documented in wp-admin/includes/file.php */
return apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $wp_filetype['type'], 'error' => false), 'sideload');
}
开发者ID:hpilevar,项目名称:WordPress,代码行数:83,代码来源:functions.php
示例17: postie_handle_upload
function postie_handle_upload(&$file, $overrides = false, $time = null)
{
// The default error handler.
if (!function_exists('wp_handle_upload_error')) {
function wp_handle_upload_error(&$file, $message)
{
return array('error' => $message);
}
}
// You may define your own function and pass the name in $overrides['upload_error_handler']
$upload_error_handler = 'wp_handle_upload_error';
// $_POST['action'] must be set and its value must equal $overrides['action'] or this:
$action = 'wp_handle_upload';
// Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
$upload_error_strings = array(false, __("The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."), __("The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."), __("The uploaded file was only partially uploaded."), __("No file was uploaded."), '', __("Missing a temporary folder."), __("Failed to write file to disk."));
// Install user overrides. Did we mention that this voids your warranty?
if (is_array($overrides)) {
extract($overrides, EXTR_OVERWRITE);
}
// A successful upload will pass this test. It makes no sense to override this one.
if ($file['error'] > 0) {
return $upload_error_handler($file, $upload_error_strings[$file['error']]);
}
// A non-empty file will pass this test.
if (!($file['size'] > 0)) {
return $upload_error_handler($file, __('File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini.'));
}
// A properly uploaded file will pass this test. There should be no reason to override this one.
if (!file_exists($file['tmp_name'])) {
return $upload_error_handler($file, __('Specified file failed upload test.'));
}
// A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
$wp_filetype = wp_check_filetype($file['name']);
DebugEcho("postie_handle_upload: detected file type for " . $file['name'] . " is " . $wp_filetype['type']);
extract($wp_filetype);
if ((!$type || !$ext) && !current_user_can('unfiltered_upload')) {
return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.'));
}
if (!$ext) {
$ext = ltrim(strrchr($file['name'], '.'), '.');
}
if (!$type) {
$type = $file['type'];
}
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
if (!(($uploads = wp_upload_dir($time)) && false === $uploads['error'])) {
return $upload_error_handler($file, $uploads['error']);
}
// fix filename (encode non-standard characters)
$file['name'] = filename_fix($file['name']);
$filename = wp_unique_filename($uploads['path'], $file['name']);
DebugEcho("wp_unique_filename: {$filename}");
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/{$filename}";
if (false === @rename($file['tmp_name'], $new_file)) {
DebugEcho("upload: rename failed");
DebugEcho("new file: {$new_file}");
//DebugDump($file);
//DebugDump($uploads);
return $upload_error_handler($file, sprintf(__('The uploaded file could not be moved to %s.'), $uploads['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}";
$return = apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type));
return $return;
}
开发者ID:donwea,项目名称:nhap.org,代码行数:70,代码来源:postie-functions.php
示例18: copy_post_image
private static function copy_post_image($url, $post_id)
{
$time = current_time('mysql');
if ($post = get_post($post_id)) {
if (substr($post->post_date, 0, 4) > 0) {
$time = $post->post_date;
}
}
//making sure there is a valid upload folder
if (!(($uploads = wp_upload_dir($time)) && false === $uploads['error'])) {
return false;
}
$name = basename($url);
$filename = wp_unique_filename($uploads['path'], $name);
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/{$filename}";
$uploaddir = wp_upload_dir();
$path = str_replace($uploaddir['baseurl'], $uploaddir['basedir'], $url);
if (!copy($path, $new_file)) {
return false;
}
// Set correct file permissions
$stat = stat(dirname($new_file));
$perms = $stat['mode'] & 0666;
@chmod($new_file, $perms);
// Compute the URL
$url = $uploads['url'] . "/{$filename}";
if (is_multisite()) {
delete_transient('dirsize_cache');
}
$type = wp_check_filetype($new_file);
return array('file' => $new_file, 'url' => $url, 'type' => $type['type']);
}
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:33,代码来源:forms_model.php
示例19: request
//.........这里部分代码省略.........
$pre = apply_filters('pre_http_request', false, $r, $url);
if (false !== $pre) {
return $pre;
}
if (function_exists('wp_kses_bad_protocol')) {
if ($r['reject_unsafe_urls']) {
$url = wp_http_validate_url($url);
}
if ($url) {
$url = wp_kses_bad_protocol($url, array('http', 'https', 'ssl'));
}
}
$arrURL = @parse_url($url);
if (empty($url) || empty($arrURL['scheme'])) {
return new WP_Error('http_request_failed', __('A valid URL was not provided.'));
}
if ($this->block_request($url)) {
return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
}
/*
* Determine if this is a https call and pass that on to the transport functions
* so that we can blacklist the transports that do not support ssl verification
*/
$r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
// Determine if this request is to OUR install of WordPress.
$homeURL = parse_url(get_bloginfo('url'));
$r['local'] = 'localhost' == $arrURL['host'] || isset($homeURL['host']) && $homeURL['host'] == $arrURL['host'];
unset($homeURL);
/*
* If we are streaming to a file but no filename was given drop it in the WP temp dir
* and pick its name using the basename of the $url.
*/
if ($r['stream'] && empty($r['filename'])) {
$r['filename'] = get_temp_dir() . wp_unique_filename(get_temp_dir(), basename($url));
}
/*
* Force some settings if we are streaming to a file and check for existence and perms
* of destination directory.
*/
if ($r['stream']) {
$r['blocking'] = true;
if (!wp_is_writable(dirname($r['filename']))) {
return new WP_Error('http_request_failed', __('Destination directory for file streaming does not exist or is not writable.'));
}
}
if (is_null($r['headers'])) {
$r['headers'] = array();
}
if (!is_array($r['headers'])) {
$processedHeaders = self::processHeaders($r['headers'], $url);
$r['headers'] = $processedHeaders['headers'];
}
if (isset($r['headers']['User-Agent'])) {
$r['user-agent'] = $r['headers']['User-Agent'];
unset($r['headers']['User-Agent']);
}
if (isset($r['headers']['user-agent'])) {
$r['user-agent'] = $r['headers']['user-agent'];
unset($r['headers']['user-agent']);
}
if ('1.1' == $r['httpversion'] && !isset($r['headers']['connection'])) {
$r['headers']['connection'] = 'close';
}
// Construct Cookie: header if any cookies are set.
self::buildCookieHeader($r);
// Avoid issues where mbstring.func_overload is enabled.
开发者ID:mondi-webdigital,项目名称:prueba-wordpress,代码行数:67,代码来源:class-http.php
示例20: __construct
function __construct($form, $urlholder)
{
if (!(($uploads = wp_upload_dir()) && false === $uploads['error'])) {
wp_die($uploads['error']);
}
if (empty($_FILES[$form]['name']) && empty($_GET[$urlholder])) {
wp_die(__('Please select a file'));
}
if (!empty($_FILES)) {
$this->filename = $_FILES[$form]['name'];
} else {
if (isset($_GET[$urlholder])) {
$this->filename = $_GET[$urlholder];
}
}
//Handle a newly uploaded file, Else assume its already been uploaded
if (!empty($_FILES)) {
$this->filename = wp_unique_filename($uploads['basedir'], $this->filename);
$this->package = $uploads['basedir'] . '/' . $this->filename;
// Move the file to the uploads dir
if (false === @move_uploaded_file($_FILES[$form]['tmp_name'], $this->package)) {
wp_die(sprintf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
}
} else {
$this->package = $uploads['basedir'] . '/' . $this->filename;
}
}
开发者ID:laiello,项目名称:cartonbank,代码行数:27,代码来源:class-wp-upgrader.php
注:本文中的wp_unique_filename函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论