Results 1 to 3 of 3

Thread: Validate if uploaded file is png or jpg with php

  1. #1
    Join Date
    Mar 2013

    Validate if uploaded file is png or jpg with php

    I am using the below script to validate if uploaded files are image for a multiple upload form. Everything works but I want to further validate that the uploaded files are png or jpg only. How do I accomplish this? I am new to php so any help will be appreciated. thanks.

    PHP Code:
            $images = array();
    $pic $_FILES['file']['tmp_name'];
    $pic as $image){
    $image)) {
    $errors['image_error'] = "PNG and JPG Files ONLY.";

  2. #2
    Join Date
    Aug 2004
    Assign the results of getimagesize() to a (array) variable, then either look at index 2 for the applicable IMG_* constant value or else index 'mime' for the mime-type.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    May 2011

    The script I gave you in your previous thread has worked without error
    on over two-dozen websites for over two years. It validates according
    to what you populate the $allowtype() array with.

    Sometimes, when you re-invent the wheel, you end up with a better wheel.
    One-on-One Scripting Tuition/Mentoring

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center