Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

PHP Image Uploader - Add another extension

So I have a PHP file uploader to upload files with a watermark on it.
It totally works and it's a great script.
But it only allows JPG and JPEG extensions, and I'd like to add PNG.

I already tried this:
PHP Code

<?php 
if ($_POST['submit'] && $_FILES['userfile']['size'] <= $maxkb && !file_exists($path . $_FILES['userfile']['name']) && $_FILES['userfile']['size'] && is_uploaded_file($_FILES['userfile']['tmp_name']) && (strtolower(substr($_FILES['userfile']['name'], -3)) == "jpg" || strtolower(substr($_FILES['userfile']['name'], -4)) == "png")) 
but that doesn't work. (only the JPG and JPEG works, but I tried to add PNG but only that doesn't work)

FULL PHP CODE: http://pastebin.com/QZeiqMVw
it was too large to post on HF

Tl;dr: I need PNG to be allowed as file extension in a PHP script
pepe the frog
[Image: otsgvt.png]
Code
if ($_POST['submit'] && $_FILES['userfile']['size'] <= $maxkb && !file_exists($path . $_FILES['userfile']['name']) && $_FILES['userfile']['size'] && is_uploaded_file($_FILES['userfile']['tmp_name']) && (strtolower(substr($_FILES['userfile']['name'], -3)) == "jpg" || strtolower(substr($_FILES['userfile']['name'], -3)) == "png"))

The substr() for PNG only needs to be set to -3.

Having it set to -4 means it goes back 4 characters and would be capturing ".png", so it would return false as you are comparing it to "png".
Bit of a stupid way when you can just get the MIME type of the file. Ref: http://php.net/manual/en/function.finfo-file.php
I only use https://ricochet.im - ricochet:lmi3tdtlsnziqwdk

Jabber: [email protected]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[The Brotherhood] by VinavilMar 27, 2026 09:05 AM 25 859 Mar 27, 2026 09:05 AM
Last Post: Vinavil
[PHP] by BulgarianFeb 21, 2020 12:33 AM 5 372 Feb 21, 2020 12:33 AM
Last Post: Backbone
[PHP] by LynxFeb 7, 2019 12:11 AM 10 312 Feb 7, 2019 12:11 AM
Last Post: Lynx