0 ) {
require_once( dirname(__FILE__) . '/../../../../wp-load.php' );
// Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
if ( is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
$_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie'];
elseif ( empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie']) )
$_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
@header('Content-Type: text/html; charset=' . get_option('blog_charset'));
require_once(ABSPATH. 'wp-admin/includes/image.php' ); // Connect image resize functions
function wpdev_make_file_upload( &$file, $dir , $url ) {
// The default error handler.
if (! function_exists( 'wp_handle_upload_error' ) ) { function wp_handle_upload_error( &$file, $message ) { return array( 'error'=>$message ); } }
// 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." ));
// A successful upload will pass this test. It makes no sense to override this one.
if ( $file['error'] > 0 ) return wp_handle_upload_error( $file, $upload_error_strings[$file['error']] );
// A non-empty file will pass this test.
if ( !($file['size'] > 0 ) ) return wp_handle_upload_error( $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_uploaded_file( $file['tmp_name'] ) ) return wp_handle_upload_error( $file, __( 'Specified file failed upload test.' ));
// If you override this, you must provide $ext and $type!!!!
$test_type = true;
$mimes = false;
// A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
$wp_filetype = wp_check_filetype( $file['name'], $mimes );
extract( $wp_filetype );
if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) return wp_handle_upload_error( $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 ( ! isset( $dir) ) return wp_handle_upload_error( $file, __('Source upload directory is not set') );
$filename = wp_unique_filename( $dir, $file['name'], null );
// Move the file to the uploads dir
$new_file = $dir . "/$filename";
if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) return wp_handle_upload_error( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $dir ) );
// Set correct file permissions
$stat = stat( dirname( $new_file ));
$perms = $stat['mode'] & 0000666;
@ chmod( $new_file, 0766 /*$perms */);
// Compute the URL
$url = $url . "/$filename";
return array( 'file' => $new_file, 'url' => $url, 'type' => $type ) ;
}
//debuge($_REQUEST);
////////////
$file = wpdev_make_file_upload($_FILES['wpdev-async-upload'], $_REQUEST['dir_icons'], $_REQUEST['url_icons']);
if ( isset($file['error']) ) { echo $file['error'] ; return 0; }
$url = $file['url'];
$type = $file['type'];
$full_path_file = $file['file'];
$name = $_FILES['wpdev-async-upload']['name'];
$name_parts = pathinfo($name);
$ext = $name_parts['extension'];
$title = trim( substr( $name, 0, -(1 + strlen($ext)) ) );
$name_parts_real = pathinfo($full_path_file);
$file_name_only = trim( substr( $name_parts_real['basename'], 0, -(1 + strlen($ext)) ) );
$imagesize_original = getimagesize( $full_path_file );
//debuge($imagesize_original, '$imagesize_original');
//debuge($_REQUEST['size_w'], $_REQUEST["size_h"], $_REQUEST["crop"]);
if ( ( $imagesize_original[0] < $_REQUEST['size_w']) || ( $imagesize_original[1] < $_REQUEST['size_h']) ) {
$_REQUEST['size_w'] = $imagesize_original[0]-1;
$_REQUEST["size_h"] = $imagesize_original[1]-1;
}
//debuge($_REQUEST['size_w'], $_REQUEST["size_h"], $_REQUEST["crop"]);
$resized = image_resize( $full_path_file, $_REQUEST['size_w'], $_REQUEST["size_h"], $_REQUEST["crop"] );
//debuge($resized);
if (! $resized ) {
//$_REQUEST['dir_icons'], $_REQUEST['url_icons']
$previos_name = $file_name_only. '.'.$ext ;
$renamed = $file_name_only. '-'.$_REQUEST['size_w'].'x'. $_REQUEST["size_h"].'.'.$ext ;
if (! copy($_REQUEST['dir_icons'] . '/' . $previos_name, $_REQUEST['dir_icons'] . '/' . $renamed) ) {
echo '