0

I need to check the resolution of an image I want to upload via media box, and then upload it into a custom directory.

As a starting point I used part of the code from How Can I Organize the Uploads Folder by Slug (or ID, or FileType, or Author)?

And a part of it looks like this:

function wpse_25894_custom_upload_dir($path)
{   

    $use_default_dir = ( isset($_REQUEST['post_id'] ) && $_REQUEST['post_id'] == 0 ) ? true : false; 
    if( !empty( $path['error'] ) || $use_default_dir )
        return $path; //error or uploading not from a post/page/cpt 

    //THIS LINE PRODUCE ERROR. HERE I NEED TO GET WIDTH AND HEIGHT OF IMAGE I WANT TO UPLOAD
    list($width, $height) = getimagesize($path.'/'.$_POST['name']); 
    $customdir = '/'.$width.'x'.$height; //uplaod folder will be for example '640x480'

    $path['path']    = str_replace($path['subdir'], '', $path['path']); //remove default subdir (year/month)
    $path['url']     = str_replace($path['subdir'], '', $path['url']);      
    $path['subdir']  = $customdir;
    $path['path']   .= $customdir; 
    $path['url']    .= $customdir;  

    return $path;
}

$_POST['name'] contains file name of image, like 'myimage.jpg'.

1
  • what is the status of this question, is it still unsolved?
    – birgire
    May 22, 2013 at 22:16

1 Answer 1

1

In this part:

getimagesize($path.'/'.$_POST['name']); 

the variable $path is an array. Try to use

getimagesize($path['path'].'/'.$_POST['name']); 

instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.