Support » Fixing WordPress » How to restrict the image size upload for custom post type

  • Resolved Victor Rodriguez

    (@victor505)


    Hi every body. well im working on a game listing directory and i need to control the image size of the custom post, the listings (custom post) are submitted by the users and they upload the image that i use like banner of 468*60 pixels, so asking them to upload a exactly 468*60 px image doesn`t work, so i need to restrict the upload to exactly size, i mean if a user want to upload a image with differente size the form restrict the upload until the user has the matching size.

    There is a way to do it , can you give a hint with this, thanks.

    P.D. By the way I know that i can set up custom image size in wordpress but that doesnt restrict the upload just crop or resize the original image , the result is quite different from the original image, so i need another solution.

Viewing 3 replies - 1 through 3 (of 3 total)
  • wpismypuppet

    (@wordpressismypuppet)

    Sounds like what you are looking for is to check the dimensions of the file being uploaded and then either accepting or denying it’s existence based on that!

    If this is the case, it’s involved… you’ll need PHP’s getimagesize() function and then right conditions based off your findings. Keep in mind that you’ll probably have to pair that with something to check the file extension first and make sure it’s actually an image.

    Now I know some will say that this can be accomplished by JavaScript… and I agree! However, JavaScript can easily be disabled and if that’s your ONLY solution, it will fail.

    You’ll want a JavaScript front end check for immediate feedback, and then a PHP fallback to handle people who try to bypass stuff.

    Yes, You`re right, I want to check the image dimension and acepting if this match the defined dimension,thanks you very much to put me in the rigth direction, your suggestion to use both JavaScript and PHP is great idea, I going to check the function getimagesize() to see sintax and arrays.

    Im prety sure that is the best way to do it because wordpress doesn´t have
    a function to check the dimensions of files uploaded, thanks again.

    wpismypuppet

    (@wordpressismypuppet)

    No problem… let me know how it works out.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to restrict the image size upload for custom post type’ is closed to new replies.