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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.