Support » Fixing WordPress » How to set/force maximum photo dimensions when uploading

  • Resolved gorvie

    (@gorvie)


    When a user uploads a large photo, lets say 3000 x 3000, They hit a 500 Internal server error on my website. Wasnt able to fix that, so how can i force max dimensions
    Here is my current code:

    <?php
    $betubeCustomUpload = $redux_demo[‘betube-custom-uploading’];
    if($betubeCustomUpload == 1){
    ?>
    <div class=”upload-image”>
    <label for=”imgfileupload” class=”btn-upload”>
    <i class=”fa fa-camera”></i>
    <span>
    <?php esc_html_e(“Featured Image”, ‘betube’) ?>

    </span>
    </label>
    <input type=”file” id=”imgfileupload” name=”upload_attachment[]” multiple=”false” accept=”image/png, image/jpeg”>

    </div>
    <?php }?>

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • How are you so sure that the maximum dimensions are triggering the 500 error. Do you have some sort of logged message of this?

    Anyways I found a script that with some changes would solve your wish: GitHub Snippet.

    I’m not completely sure whether $file contains the dimensions. If so this filter could be the soluction.

    • This reply was modified 3 months, 2 weeks ago by basvandijkk.
    • This reply was modified 3 months, 2 weeks ago by basvandijkk.

    Tried this code but, seems to be for image size only. Trying to figure out how to apply dimensions rather than size.

    If i could just fix the issue of users not being able to load large photos that would be nice.. I recall media page giving error saying try photo that is less than 2500 x 2500 etc. i see that users attempt to upload 3000 x 3000 and that’s when they hit the 500 error. The post still goes through, just the featured image isnt set..

    But the code provided ghosts the image when user uploads large photos, but no error message and the post still goes through, just no image.

    Idealy trying to get something that blocks large photos based on their dimensions and returns message (preferably)

    Thanks again

    Ok i found this code to limit dimensions. seems to work.
    https://www.webempresa.com/foro/administracion-wordpress/limitar-tamano-de-imagen-subida-a-la-libreria-multimedia

    Only issue is that there is no warning that image is too large, etc. the post still gets published but just with a blank image. This is better than the 500 error althoe.

    Any idea how to tweak it to show warning and disable the use of large photos etc?

    thanks

    Nice that seems to be a way indeed. Getting the dimensions like that! What happens when you return false; when the image doesn’t meet your conditions?

    gorvie

    (@gorvie)

    Sorry for the late response. Had to take some down time.. I tried return false; but didn’t seem to do anything. When image is too large, it wont set.. just a fallback thumbnail. I put a warning on the upload page saying photo must be 2500 x 2500 or under but it seems people are still uploading larger photos resulting in the default thumbnail. Would be ideal to return error telling them photo is too large.

    the code im using in functions seems to show a error but im not seeing it happen on my end:
    https://www.webempresa.com/foro/administracion-wordpress/limitar-tamano-de-imagen-subida-a-la-libreria-multimedia

    Any other ideas?

    Thanks again.

    basvandijkk

    (@basvandijkk)

    I came across this post: StackExchange

    I know I already pointed you to this filter. But it really looks like this is the solution. I could help you further if I know more about your code. Like the PHP side about how the form is being handled.

    gorvie

    (@gorvie)

    I was able to find this in the thread: https://wordpress.org/plugins/imsanity/

    Seems to be working. Resizes large images when uploading.

    Thank you for your time and help. Was really an issue that needed to fix.

    Amazing.

    basvandijkk

    (@basvandijkk)

    Glad you found a solution!

    • This reply was modified 3 months ago by basvandijkk. Reason: grammar
Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.