Jump to content

html form with file input / label


Imaulle

Recommended Posts

Hello,

 

ok so I need to have an image to replace the normal file input button but nothing happens when I click the image. What am I doing wrong?

 

<form action="../../uploads/social_handler/<?php echo $row->id; ?>/" method="post" enctype="multipart/form-data">
    <input type="file" style="display:none" id="fileInput<?php echo $row->id; ?>" name="fileInput<?php echo $row->id; ?>">
    <label for="fileInput<?php echo $row->id; ?>">
        <img src="../../assets/adminIcons/replaceimage24.png">
    </label>
</form>

 

 

Also, how will I control the file input stuff so that they can only upload png files?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/261624-html-form-with-file-input-label/
Share on other sites

Just using an image won't do anything. It has to be an input with type=image.


 

For validating the file type, the best way is for the script to use a function like getimagesize to find out (a) whether the file is an image and (b) what type of image it is. If it isn't a PNG (or even an image at all) then you can do whatever you'd like.

If anybody tells you to use $_FILES["fileInputX"]["type"] they are wrong.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.