<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[29209] trunk/src/wp-admin/includes/file.php: Merge `wp_handle_upload()` and `wp_handle_sideload()` by making them each wrap a new function: `_wp_handle_upload()`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/29209">29209</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-07-17 18:57:26 +0000 (Thu, 17 Jul 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge `wp_handle_upload()` and `wp_handle_sideload()` by making them each wrap a new function: `_wp_handle_upload()`.
Props DrewAPicture for docs.
Fixes <a href="http://core.trac.wordpress.org/ticket/23686">#23686</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesfilephp">trunk/src/wp-admin/includes/file.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesfilephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/file.php (29208 => 29209)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/file.php 2014-07-17 17:41:06 UTC (rev 29208)
+++ trunk/src/wp-admin/includes/file.php 2014-07-17 18:57:26 UTC (rev 29209)
</span><span class="lines">@@ -191,36 +191,35 @@
</span><span class="cx"> * Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type,
</span><span class="cx"> * and moving the file to the appropriate directory within the uploads directory.
</span><span class="cx"> *
</span><del>- * @since 2.0.0
</del><ins>+ * @since 4.0.0
</ins><span class="cx"> *
</span><del>- * @uses wp_handle_upload_error
- * @uses is_multisite
- * @uses wp_check_filetype_and_ext
- * @uses current_user_can
- * @uses wp_upload_dir
- * @uses wp_unique_filename
- * @uses delete_transient
- * @param array $file Reference to a single element of $_FILES. Call the function once for each uploaded file.
- * @param array $overrides Optional. An associative array of names=>values to override default variables.
- * @param string $time Optional. Time formatted in 'yyyy/mm'.
- * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
- */
-function wp_handle_upload( &$file, $overrides = false, $time = null ) {
</del><ins>+ * @see wp_handle_upload_error
+ *
+ * @param array $file Reference to a single element of $_FILES. Call the function once for
+ * each uploaded file.
+ * @param array $overrides An associative array of names => values to override default variables.
+ * @param string $time Time formatted in 'yyyy/mm'.
+ * @param string $action Expected value for $_POST['action'].
+ * @return array On success, returns an associative array of file attributes. On failure, returns
+ * $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
+*/
+function _wp_handle_upload( &$file, $overrides, $time, $action ) {
</ins><span class="cx"> // The default error handler.
</span><span class="cx"> if ( ! function_exists( 'wp_handle_upload_error' ) ) {
</span><span class="cx"> function wp_handle_upload_error( &$file, $message ) {
</span><del>- return array( 'error'=>$message );
</del><ins>+ return array( 'error' => $message );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Filter data for the current file to upload.
</del><ins>+ * The dynamic portion of the hook name, $action, refers to the post action.
</ins><span class="cx"> *
</span><del>- * @since 2.9.0
</del><ins>+ * @since 2.9.0 as 'wp_handle_upload_prefilter'
+ * @since 4.0.0 Converted to a dynamic hook with $action
</ins><span class="cx"> *
</span><span class="cx"> * @param array $file An array of data for a single file.
</span><span class="cx"> */
</span><del>- $file = apply_filters( 'wp_handle_upload_prefilter', $file );
</del><ins>+ $file = apply_filters( "{$action}_prefilter", $file );
</ins><span class="cx">
</span><span class="cx"> // You may define your own function and pass the name in $overrides['upload_error_handler']
</span><span class="cx"> $upload_error_handler = 'wp_handle_upload_error';
</span><span class="lines">@@ -229,8 +228,9 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // You may have had one or more 'wp_handle_upload_prefilter' functions error out the file. Handle that gracefully.
</span><del>- if ( isset( $file['error'] ) && !is_numeric( $file['error'] ) && $file['error'] )
</del><ins>+ if ( isset( $file['error'] ) && ! is_numeric( $file['error'] ) && $file['error'] ) {
</ins><span class="cx"> return $upload_error_handler( $file, $file['error'] );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Install user overrides. Did we mention that this voids your warranty?
</span><span class="cx">
</span><span class="lines">@@ -240,42 +240,39 @@
</span><span class="cx"> $unique_filename_callback = $overrides['unique_filename_callback'];
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
- $action = 'wp_handle_upload';
- if ( isset( $overrides['action'] ) ) {
- $action = $overrides['action'];
- }
-
- // 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 upload_max_filesize directive in php.ini." ),
- __( "The uploaded file exceeds the MAX_FILE_SIZE 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." ),
- __( "File upload stopped by extension." ));
-
</del><span class="cx"> /*
</span><span class="cx"> * This may not have orignially been intended to be overrideable,
</span><span class="cx"> * but historically has been.
</span><span class="cx"> */
</span><span class="cx"> if ( isset( $overrides['upload_error_strings'] ) ) {
</span><span class="cx"> $upload_error_strings = $overrides['upload_error_strings'];
</span><ins>+ } else {
+ // 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 upload_max_filesize directive in php.ini.' ),
+ __( 'The uploaded file exceeds the MAX_FILE_SIZE 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.' ),
+ __( 'File upload stopped by extension.' )
+ );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // All tests are on by default. Most can be turned off by $overrides[{test_name}] = false;
</span><span class="cx"> $test_form = isset( $overrides['test_form'] ) ? $overrides['test_form'] : true;
</span><span class="cx"> $test_size = isset( $overrides['test_size'] ) ? $overrides['test_size'] : true;
</span><del>- $test_upload = isset( $overrides['test_upload'] ) ? $overrides['test_upload'] : true;
</del><span class="cx">
</span><span class="cx"> // If you override this, you must provide $ext and $type!!
</span><span class="cx"> $test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
</span><span class="cx"> $mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : false;
</span><span class="cx">
</span><ins>+ $test_upload = isset( $overrides['test_upload'] ) ? $overrides['test_upload'] : true;
+
</ins><span class="cx"> // A correct form post will pass this test.
</span><del>- if ( $test_form && ( ! isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) {
</del><ins>+ if ( $test_form && ( ! isset( $_POST['action'] ) || ( $_POST['action'] != $action ) ) ) {
</ins><span class="cx"> return call_user_func( $upload_error_handler, $file, __( 'Invalid form submission.' ) );
</span><span class="cx"> }
</span><span class="cx"> // A successful upload will pass this test. It makes no sense to override this one.
</span><span class="lines">@@ -283,18 +280,22 @@
</span><span class="cx"> return call_user_func( $upload_error_handler, $file, $upload_error_strings[ $file['error'] ] );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ $test_file_size = 'wp_handle_upload' === $action ? $file['size'] : filesize( $file['tmp_name'] );
</ins><span class="cx"> // A non-empty file will pass this test.
</span><del>- if ( $test_size && !($file['size'] > 0 ) ) {
- if ( is_multisite() )
</del><ins>+ if ( $test_size && ! ( $test_file_size > 0 ) ) {
+ if ( is_multisite() ) {
</ins><span class="cx"> $error_msg = __( 'File is empty. Please upload something more substantial.' );
</span><del>- else
</del><ins>+ } else {
</ins><span class="cx"> $error_msg = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' );
</span><del>- return call_user_func($upload_error_handler, $file, $error_msg);
</del><ins>+ }
+ return call_user_func( $upload_error_handler, $file, $error_msg );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // A properly uploaded file will pass this test. There should be no reason to override this one.
</span><del>- if ( $test_upload && ! @ is_uploaded_file( $file['tmp_name'] ) )
- return call_user_func($upload_error_handler, $file, __( 'Specified file failed upload test.' ));
</del><ins>+ $test_uploaded_file = 'wp_handle_upload' === $action ? @ is_uploaded_file( $file['tmp_name'] ) : @ is_file( $file['tmp_name'] );
+ if ( $test_upload && ! $test_uploaded_file ) {
+ return call_user_func( $upload_error_handler, $file, __( 'Specified file failed upload test.' ) );
+ }
</ins><span class="cx">
</span><span class="cx"> // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
</span><span class="cx"> if ( $test_type ) {
</span><span class="lines">@@ -321,19 +322,29 @@
</span><span class="cx"> * A writable uploads dir will pass this test. Again, there's no point
</span><span class="cx"> * overriding this one.
</span><span class="cx"> */
</span><del>- if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) )
- return call_user_func($upload_error_handler, $file, $uploads['error'] );
</del><ins>+ if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) {
+ return call_user_func( $upload_error_handler, $file, $uploads['error'] );
+ }
</ins><span class="cx">
</span><span class="cx"> $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
</span><ins>+ // Strip the query strings.
+ $filename = str_replace( '?', '-', $filename );
+ $filename = str_replace( '&', '-', $filename );
</ins><span class="cx">
</span><span class="cx"> // Move the file to the uploads dir.
</span><span class="cx"> $new_file = $uploads['path'] . "/$filename";
</span><del>- if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) {
- if ( 0 === strpos( $uploads['basedir'], ABSPATH ) )
</del><ins>+ if ( 'wp_handle_upload' === $action ) {
+ $move_new_file = @ move_uploaded_file( $file['tmp_name'], $new_file );
+ } else {
+ $move_new_file = @ rename( $file['tmp_name'], $new_file );
+ }
+
+ if ( false === $move_new_file ) {
+ if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
</ins><span class="cx"> $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
</span><del>- else
</del><ins>+ } else {
</ins><span class="cx"> $error_path = basename( $uploads['basedir'] ) . $uploads['subdir'];
</span><del>-
</del><ins>+ }
</ins><span class="cx"> return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $error_path ) );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -345,8 +356,9 @@
</span><span class="cx"> // Compute the URL.
</span><span class="cx"> $url = $uploads['url'] . "/$filename";
</span><span class="cx">
</span><del>- if ( is_multisite() )
</del><ins>+ if ( is_multisite() ) {
</ins><span class="cx"> delete_transient( 'dirsize_cache' );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Filter the data array for the uploaded file.
</span><span class="lines">@@ -360,151 +372,69 @@
</span><span class="cx"> * @type string $url URL of the uploaded file.
</span><span class="cx"> * @type string $type File type.
</span><span class="cx"> * }
</span><del>- * @param string $context The type of upload action. Accepts 'upload' or 'sideload'.
</del><ins>+ * @param string $context The type of upload action. Values include 'upload' or 'sideload'.
</ins><span class="cx"> */
</span><del>- return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' );
</del><ins>+ return apply_filters( 'wp_handle_upload', array(
+ 'file' => $new_file,
+ 'url' => $url,
+ 'type' => $type
+ ), 'wp_handle_sideload' === $action ? 'sideload' : 'upload' ); }
+
+/**
+ * Wrapper for _wp_handle_upload(), passes 'wp_handle_upload' action.
+ *
+ * @since 2.0.0
+ *
+ * @see _wp_handle_upload()
+ *
+ * @param array $file Reference to a single element of $_FILES. Call the function once for
+ * each uploaded file.
+ * @param array|bool $overrides Optional. An associative array of names=>values to override default
+ * variables. Default false.
+ * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
+ * @return array On success, returns an associative array of file attributes. On failure, returns
+ * $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
+ */
+function wp_handle_upload( &$file, $overrides = false, $time = null ) {
+ /*
+ * $_POST['action'] must be set and its value must equal $overrides['action']
+ * or this:
+ */
+ $action = 'wp_handle_upload';
+ if ( isset( $overrides['action'] ) ) {
+ $action = $overrides['action'];
+ }
+
+ return _wp_handle_upload( $file, $overrides, $time, $action );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Handle sideloads, which is the process of retrieving a media item from another server instead of
- * a traditional media upload. This process involves sanitizing the filename, checking extensions
- * for mime type, and moving the file to the appropriate directory within the uploads directory.
</del><ins>+ * Wrapper for _wp_handle_upload(), passes 'wp_handle_sideload' action
</ins><span class="cx"> *
</span><span class="cx"> * @since 2.6.0
</span><span class="cx"> *
</span><del>- * @uses wp_handle_upload_error
- * @uses wp_check_filetype_and_ext
- * @uses current_user_can
- * @uses wp_upload_dir
- * @uses wp_unique_filename
- * @param array $file an array similar to that of a PHP $_FILES POST array
- * @param array $overrides Optional. An associative array of names=>values to override default variables.
- * @param string $time Optional. Time formatted in 'yyyy/mm'.
- * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
</del><ins>+ * @see _wp_handle_upload()
+ *
+ * @param array $file An array similar to that of a PHP $_FILES POST array
+ * @param array|bool $overrides Optional. An associative array of names=>values to override default
+ * variables. Default false.
+ * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
+ * @return array On success, returns an associative array of file attributes. On failure, returns
+ * $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
</ins><span class="cx"> */
</span><span class="cx"> function wp_handle_sideload( &$file, $overrides = false, $time = null ) {
</span><del>- // The default error handler.
- if (! function_exists( 'wp_handle_upload_error' ) ) {
- function wp_handle_upload_error( &$file, $message ) {
- return array( 'error'=>$message );
- }
- }
-
- // Install user overrides. Did we mention that this voids your warranty?
-
- // You may define your own function and pass the name in $overrides['upload_error_handler']
- $upload_error_handler = 'wp_handle_upload_error';
- if ( isset( $overrides['upload_error_handler'] ) ) {
- $upload_error_handler = $overrides['upload_error_handler'];
- }
-
- // You may define your own function and pass the name in $overrides['unique_filename_callback']
- $unique_filename_callback = null;
- if ( isset( $overrides['unique_filename_callback'] ) ) {
- $unique_filename_callback = $overrides['unique_filename_callback'];
- }
-
- // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
</del><ins>+ /*
+ * $_POST['action'] must be set and its value must equal $overrides['action']
+ * or this:
+ */
</ins><span class="cx"> $action = 'wp_handle_sideload';
</span><span class="cx"> if ( isset( $overrides['action'] ) ) {
</span><span class="cx"> $action = $overrides['action'];
</span><span class="cx"> }
</span><ins>+ return _wp_handle_upload( $file, $overrides, $time, $action );
+}
</ins><span class="cx">
</span><del>- // 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." ),
- __( "File upload stopped by extension." ));
</del><span class="cx">
</span><del>- // this may not have orignially been intended to be overrideable, but historically has been
- if ( isset( $overrides['upload_error_strings'] ) ) {
- $upload_error_strings = $overrides['upload_error_strings'];
- }
-
- // All tests are on by default. Most can be turned off by $overrides[{test_name}] = false;
- $test_form = isset( $overrides['test_form'] ) ? $overrides['test_form'] : true;
- $test_size = isset( $overrides['test_size'] ) ? $overrides['test_size'] : true;
-
- // If you override this, you must provide $ext and $type!!!!
- $test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
- $mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : false;
-
- // A correct form post will pass this test.
- if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) )
- return $upload_error_handler( $file, __( 'Invalid form submission.' ));
-
- // A successful upload will pass this test. It makes no sense to override this one.
- if ( ! empty( $file['error'] ) )
- return $upload_error_handler( $file, $upload_error_strings[$file['error']] );
-
- // A non-empty file will pass this test.
- if ( $test_size && !(filesize($file['tmp_name']) > 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 (! @ is_file( $file['tmp_name'] ) )
- return $upload_error_handler( $file, __( 'Specified file does not exist.' ));
-
- // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
- if ( $test_type ) {
- $wp_filetype = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], $mimes );
- $ext = empty( $wp_filetype['ext'] ) ? '' : $wp_filetype['ext'];
- $type = empty( $wp_filetype['type'] ) ? '' : $wp_filetype['type'];
- $proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename'];
-
- // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect
- if ( $proper_filename ) {
- $file['name'] = $proper_filename;
- }
- if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
- return $upload_error_handler( $file, __( 'Sorry, this file type is not permitted for security reasons.' ) );
- }
- if ( ! $type ) {
- $type = $file['type'];
- }
- } else {
- $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'] );
-
- $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
-
- // Strip the query strings.
- $filename = str_replace('?','-', $filename);
- $filename = str_replace('&','-', $filename);
-
- // Move the file to the uploads dir
- $new_file = $uploads['path'] . "/$filename";
- if ( false === @ rename( $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 $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $error_path ) );
- }
-
- // Set correct file permissions
- $stat = stat( dirname( $new_file ));
- $perms = $stat['mode'] & 0000666;
- @ chmod( $new_file, $perms );
-
- // Compute the URL
- $url = $uploads['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' => $type ), 'sideload' );
-
- return $return;
-}
-
</del><span class="cx"> /**
</span><span class="cx"> * Downloads a url to a local temporary file using the WordPress HTTP Class.
</span><span class="cx"> * Please note, That the calling function must unlink() the file.
</span></span></pre>
</div>
</div>
</body>
</html>