да не полей там несколько, поле всего одно загрузка файла на сервер в опр.папку. просто цыкл выводит несколько товаров, и в каждом из них получается есть форма загрузки.
код default.php модуля:
... if ($display_style == "div") {
?>
<div class="vmproduct<?php echo $params->get ('moduleclass_sfx'); ?> productdetails">
<?php foreach ($products as $product) { ?>
<div class="<?php echo $pwidth ?> <?php echo $float ?>">
<div class="spacer">
<div id="mod_vmprodload_name"><?php echo $product->product_name ?></div>
<div id="mod_vmprodload">
<?php
if (!empty($product->images[0])) {
$image = $product->images[0]->displayMediaThumb ('class="featuredProductImage"', FALSE);
} else {
$image = '';
}
echo JHTML::_ ('link', JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id), $image, array('title' => $product->product_name));
echo '<div class="clear"></div>';
$url = JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' .
$product->virtuemart_category_id); ?>
<a href="<?php echo $url ?>"><?php echo $product->product_name ?></a>
<?php echo '<div class="clear"></div>
</div>';
?>
<script type="text/javascript">
function hideBtn(){
jQuery('#upload').hide();
jQuery('#res').html("Идет загрузка файла");
}
function handleResponse(mes) {
jQuery('#upload').show();
if (mes.errors != null) {
jQuery('#res').html("Возникли ошибки во время загрузки файла: " + mes.errors);
}
else {
jQuery('#mod_vmprodload_link').css({'display' : 'block'});
jQuery('#mod_vmprodload_name').css({'display' : 'none'});
jQuery('#upl_label').hide();
jQuery('#upl_upload').hide();
jQuery('#res').html("Файл " + mes.name + " загружен");
jQuery('#hiddenframe').addClass('up_frame');
jQuery('#PricesalesPrice_wrap').addClass('PricesalesPrice_wrap');
}
}
jQuery(function(){
var wrapper = jQuery( ".file_upload" ),
inp = wrapper.find( "input#userfile" ),
btn = wrapper.find( "span.button" ),
lbl = wrapper.find( "mark" );
// Crutches for the :focus style:
inp.focus(function(){
wrapper.addClass( "focus" );
}).blur(function(){
wrapper.removeClass( "focus" );
});
var file_api = ( window.File && window.FileReader && window.FileList && window.Blob ) ? true : false;
inp.change(function(){
var file_name;
if( file_api && inp[ 0 ].files[ 0 ] )
file_name = inp[ 0 ].files[ 0 ].name;
else
file_name = inp.val().replace( "C:\\fakepath\\", '' );
if( ! file_name.length )
return;
if( lbl.is( ":visible" ) ){
lbl.text( file_name );
btn.text( "Выбрать" );
btn.css({'width' : '0px'});
}else
btn.text( file_name );
}).change();
});
jQuery( window ).resize(function(){
jQuery( ".file_upload input" ).triggerHandler( "change" );
});
</script>
<form action="/lambite/modules/mod_virtuemart_product/tmpl/upload.php" method="post" target="hiddenframe" enctype="multipart/form-data" onsubmit="hideBtn();">
<label id="upl_label" class="file_upload">
<span class="button">Выбрать</span>
<mark id="upl_mark">Файл не выбран</mark>
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
<input type="file" id="userfile" name="userfile" />
</label>
<input type="submit" name="upload" id="upl_upload" value="Загрузить" />
</form>
<div id="res"></div>
<iframe id="hiddenframe" class="" name="hiddenframe" style="width:0px; height:0px; border:0px"></iframe>
<?php
if ($show_price) {
// echo $currency->priceDisplay($product->prices['salesPrice']);
if (!empty($product->prices['salesPrice'])) {
echo '<div id="PricesalesPrice_wrap" class="">Цена: '.$currency->createPriceDiv ('salesPrice', '', $product->prices, FALSE, FALSE, 1.0, TRUE).'</div>';
}
// if ($product->prices['salesPriceWithDiscount']>0) echo $currency->priceDisplay($product->prices['salesPriceWithDiscount']);
if (!empty($product->prices['salesPriceWithDiscount'])) {
echo '<div class="PricesalesPrice_wrap">Цена со скидкой: '.$currency->createPriceDiv ('salesPriceWithDiscount', '', $product->prices, FALSE, FALSE, 1.0, TRUE).'</div>';
}
}
?><div id="mod_vmprodload_link"><a href="<?php echo $url ?>">Продолжить</a></div><?php
if ($show_addtocart) {
echo mod_virtuemart_product::addtocart ($product);
}
?>
</div>
</div>
<?php
if ($col == $products_per_row && $products_per_row && $col < $totalProd) {
echo " </div><div style='clear:both;'>";
$col = 1;
} else {
$col++;
}
} ?>
</div>
<br style='clear:both;'/>...
код обработчика формы upload.php:
<?php
if(isset($_POST['upload'])){
$whitelist = array(".gif", ".jpeg", ".jpg", ".png");
$data = array();
$error = true;
foreach ($whitelist as $item) {
if(preg_match("/$item\$/i",$_FILES['userfile']['name'])) $error = false;
}
if(!$error) {
$folder = $_SERVER['DOCUMENT_ROOT'].'/lambite/uploads/user_img/';
$folder1 = '/lambite/uploads/user_img/';
// Генерируем случайное число
$file_name = uniqid(rand(10000,99999));
$uploadedFile = $folder.$file_name."_".basename($_FILES['userfile']['name']);
if(is_uploaded_file($_FILES['userfile']['tmp_name'])){
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadedFile)){
$data = $_FILES['userfile'];
}
else {
$data['errors'] = "Во время загрузки файла произошла ошибка";
}
}
else {
$data['errors'] = "Проверьте размер или целостность файла";
}
}
else{
$data['errors'] = 'Вы загружаете запрещенный тип файла';
}
//Формируем js-файл
$res = '<script type="text/javascript">';
$res .= "var data = new Object;";
foreach($data as $key => $value){
$res .= 'data.'.$key.' = "'.$value.'";';
}
$res .= 'window.parent.handleResponse(data);';
$res .= "</script>";
echo $res;
echo '<div>
<img src="'.$uploadedFile1.'" alt="Ваш оттиск" style="width: 160px; height: 160px; margin: -8px;">
</div>';
}
else{
die("ERROR");
}
?>