user2516546
user2516546

Reputation: 111

Upload file using text link instad of input

I know there are a few posts about this already but the answers in some seem to have caused some controversy so, I'm wondering if there's a "foolproof" way of triggering the file upload without using an input field. Basically what I want to do id to have a div with an Icon & text link which triggers the file upload when you click it. Kind of like:

.upload{
padding: 5px 10px 5px 30px;
background: url() center left no-repeat;
}
<div class="upload">(icon) Click here to add a photo</div>

Any help or advice would be hugely appreciated, thank you.

Upvotes: 2

Views: 1595

Answers (1)

DeiForm
DeiForm

Reputation: 664

Add to your html this:

<input id="article_file_input" type="file" name="article_picture" style="display: none;">

And to make anchor:

<a onclick="$('input[id=article_file_input]').click();">Click here to add files</a>

Upvotes: 5

Related Questions