Курсовые работы / ПРИС П _1
.pdf</form>
<br>
</div>
<script type="text/javascript" src="/send_mail_form/valid.js"></script> <script>
$(document).ready( function() {
$(".file-upload input[type=file]").change(function(){ $("#filename").text('Загружено');
});
});
</script>
Фрагмент исходного кода программы (компонент для предзагрузки файлов формы подачи заявок для клиентов)
<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); if(!empty($_FILES) && empty($_POST['FORM_SUBMIT']))
{
Header('Content-type:application/json;');
CModule::IncludeModule('iblock');
$arImageTypes = Array(
'image/gif',
'image/jpeg',
'image/png',
'image/bmp',
'text/plain',
'application/downloads',
'application/xml',
'application/msword',
'application/pdf',
'application/rtf', 'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
); $APPLICATION->RestartBuffer(); $arImages = Array(); if(!empty($_FILES)){
foreach($_FILES['PHOTO']['name'] as $k=>$i){ $arImages[$k] = Array(
'name' => $_FILES['PHOTO']['name'][$k],
42
'type' => $_FILES['PHOTO']['type'][$k],
'tmp_name' => $_FILES['PHOTO']['tmp_name'][$k], 'error' => $_FILES['PHOTO']['error'][$k],
'size' => $_FILES['PHOTO']['size'][$k]
);
}
$arIDS = Array(); foreach($arImages as $k=>$i){
if(
$i['error'] == 0 && in_array($i['type'],$arImageTypes) && !empty($i['tmp_name'])
){
$i["MODULE_ID"] = "i_orders"; $fid = CFile::SaveFile($i, "i_orders"); if(!empty($fid))
{
$arTmb = Array(); if(strripos($i['type'],'image/') !== False){
$arTmb = CFile::ResizeImageGet($fid,Array('width'=>100,'height'=>100),BX_RESIZE_IMAGE_EXACT,false);
} else {
$arTmb['src'] = '/images/file.png';
}
$arIDS[$fid] = Array(
'id' => $fid,
'name' => $i['name'],
'path' => CFile::GetPath($fid), 'tmb' => $arTmb
);
}
}
}
}
print(json_encode($arIDS)); exit;
}
$this->IncludeComponentTemplate(); ?>
<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
43
$component_id = randString(10); ?>
<div class="button-block">
<label>При необходимости вы можете прикрепить файлы (фото или документацию)</label> <div class="mb20">
<small>
Используйте кнопку SHIFT или CTRL<br>
для добавления нескольких фото
</small>
</div>
<a href="javascript:void(0)" class="btn-upload-file b-one">
<input accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms- excel,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document, image/*" type="file" name="PHOTO[]" multiple="multiple" id="file_<?=$component_id?>">
<span> Прикрепить</span>
</a>
<a class="b-two" href="javascript:void(0)" onclick="$('#tmb_area_<?=$component_id?>').html('<div class=\'clr\'></div>').fadeOut()">Отмена</a>
<div class="clr"></div>
<div class="i-file-area" id="tmb_area_<?=$component_id?>"><div class="clr"></div></div> <script type="text/javascript">
$(function(){
var Uploader__<?=$component_id?> = new IMGUploader({'file_id':'file_<?=$component_id?>','img_id':'tmb_area_<?=$component_id?>'})
})
</script>
</div>
function IMGUploader(params)
{
this.params = params
this.form = false
this.init()
}
IMGUploader.prototype = { constructor : IMGUploader, init : function(){
var self = this
document.getElementById( self.params.file_id ).addEventListener('change', function( e ){ self.download( self )
})
44
},
progress : function( e )
{
return e
},
download : function(self)
{
self.form = $('#' + self.params.file_id).parents('form')[0] self.upload(self,document.getElementById( self.params.file_id ))
},
upload : function(self,file)
{
var file = $(file) self.preloader('start',file) $.ajax({
url: '?AJAX_LOAD=Y', type: 'POST',
xhr: function(){
myXhr = $.ajaxSettings.xhr();
if(myXhr.upload) myXhr.upload.addEventListener('progress',self.progress, false); return myXhr;
},
success: function(arIDS)
{
self.preloader('remove',file)
if(arIDS)
{
self.arPhotoIDS = arIDS
var area = $('#' + self.params.img_id) area.html('<div class="clr"></div>') for(k in self.arPhotoIDS)
{
__img = self.arPhotoIDS[k]
var __wrapDOM =
$(document.createElement('div')).addClass('tmb-image-wrapper')
var __lnRemoveDOM =
$(document.createElement('a')).attr({
'href': 'javascript:void(0)',
'onclick': '$(this).parent(".tmb-image-
wrapper").remove()',
'title' : __img.name }).addClass('i-remove-file')
45
var __imgDOM =
$(document.createElement('img')).attr({'src': __img.tmb.src})
var __fileDOM = $(document.createElement('input')).attr({'value': __img.id,'name':'PHOTO[]','type':'hidden'})
area.prepend(__wrapDOM.append(__lnRemoveDOM).append(__imgDOM).append(__fileDOM))
}
}
},
data: new FormData(self.form), cache: false,
contentType: false, processData: false
})
},
preloader : function(action,file)
{
var self = this
var txt_area = $(file).parents('a').find('span') var imgArea = $('#' + self.params.img_id)
if(typeof($('#preloaderByUpload')[0]) === 'undefined')
{
preloader = $(document.createElement('div')).attr({ 'id' : 'preloaderByUpload'
}).css({
'position' : 'fixed', 'width' : '100%', 'height' : '100%', 'left' : '0px', 'right' : '0px', 'top' : '0px', 'bottom' : '0px',
'background' : 'rgba(255,255,255,0.5)', 'text-align' : 'center',
'display' : 'none', 'z-index' : '10'
}).html('<div class="table"><div class="cell"><img src="/images/preloader.gif"></div></div>')
$('body').append(preloader)
}
if(action == 'start')
{
46
imgArea.fadeOut() $('#preloaderByUpload').fadeIn() txt_area.text('Загрузка файлов ...')
}
else if(action == 'remove')
{
imgArea.fadeIn() $('#preloaderByUpload').fadeOut() txt_area.text('Загрузка завершена')
}
}
}
47