jquery file input image preview before it is uploaded
jquery file input image preview before it is uploaded
HTML
<div class="postarea">
<a id="postbox"></a>
<form name="postform" id="postform" action="http://www.deachrysal.is/board.php" method="post" enctype="multipart/form-data">
<table class="postform">
<tbody>
<tr>
<td class="postblock">
Тема
</td>
<td>
<input type="text" name="subject" size="35" maxlength="75" accesskey="s"> <input type="submit" value="Отправить" accesskey="z"> (<span id="posttypeindicator">новый тред</span>)
</td>
</tr>
<tr>
<td class="postblock2">
Сообщение
</td>
<td>
<textarea name="message" cols="48" rows="6" accesskey="m"></textarea>
</td>
</tr>
<tr>
<td class="postblock">
Файл
</td>
<td>
<span id="fileInputContainer">
<input type="file" name="imagefile" size="35" accesskey="f" id="fileInput">
</span>
<input type="checkbox" name="spoiler" id="spoiler"><label for="spoiler">Спойлер</label>
<br><a onclick="clearFileInputField('fileInputContainer'); return false;" href="#">Очистить</a>
</td>
</tr>
<tr>
<td class="postblock">
URL</td>
<td>
<span id="fileInputContainer">
<input type="text" name="fileurl" size="48" accesskey="h" id="fileInput">
</span>
</td>
</tr>
<tr>
<td class="postblock">
Пароль
</td>
<td>
<input type="password" name="postpassword" size="8" accesskey="p"> (для удаления постов и файлов)
</td>
</tr>
<tr id="trgetback">
<td class="postblock">Обратно</td>
<td>
<label><input name="redirecttothread" value="0" type="radio"> к доске</label> <label><input name="redirecttothread" value="1" checked="checked" type="radio"> к треду</label>
</td>
</tr><tr id="passwordbox"><td></td><td></td></tr>
<tr>
<td colspan="2" class="rules">
<ul style="margin-left: 0; margin-top: 0; margin-bottom: 0; padding-left: 0;">
<li>Читайте <a href="http://www.deachrysal.is/news.php?p=rules">правила</a>, они интересные.</li>
<li>Есть вопросы? Читайте <a href="http://www.deachrysal.is/news.php?p=faq">FAQ</a>.</li>
<li>Поддерживаемые типы файлов:
GIF,
JPG,
PNG,
RAR,
SWF,...
CSS
/*input#post_file{background-image:url(); background-color:#FFF; border: 1px white solid; border-radius:10px;}*/
[type="submit"],[type="button"],[type="reset"],[type="file"],[type="text"], textarea{
color:#000000 !important;
}
.postblock {
background: transparent;
color: RGB(0, 34, 68);
font-weight: bold;
}
.postform,.postblock2, .postblock {border: 1px solid black;}
JavaScript
$(".postform").after("<div id='test123'></div>");
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('.postblock2').css({'background-image': 'url(' + e.target.result + ')', 'color': 'transparent' , 'height':'250px', 'width':'250px', 'background-repeat':'no-repeat', 'background-size':'cover'});
}
reader.readAsDataURL(input.files[0]);
}
}
$("#fileInput").change(function () {
readURL(this);
});