我與Joomla MVC做的模型我有一個XML文件:
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
<field name="seleccione" type="file" class="inputbox" accept="xls"
label="COM_EMPRESA_FORM_LBL_CARGA_MASIVA" description="COM_EMPRESA_FORM_DESC_CARGA_MASIVA"
required="true" />
</fieldset>
</form>
,並考慮如default.php:
<?php
/**
* @version 1.0.0
* @package com_empresa
* @copyright Copyright (C) 2014. Todos los derechos reservados.
* @license Licencia Pública General GNU versión 2 o posterior. Consulte LICENSE.txt
* @author Rafael Gasperi <[email protected]> - http://www.tcontacta.com
*/
// no direct access
defined('_JEXEC') or die;
jimport('joomla.filesystem.folder');
$document = JFactory::getDocument();
//$document->addStyleSheet(JPATH_ADMINISTRATOR.'/components/com_empresa/assets/css/empresa.css');
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
//Load admin language file
$lang = JFactory::getLanguage();
$lang->load('com_empresa', JPATH_ADMINISTRATOR);
?>
<!-- Styling for making front end forms look OK -->
<!-- This should probably be moved to the template CSS file -->
<style>
.front-end-edit ul {
padding: 0 !important;
}
.front-end-edit li {
list-style: none;
margin-bottom: 6px !important;
}
.front-end-edit label {
margin-right: 10px;
display: block;
float: left;
text-align: right;
width: 200px !important;
}
.front-end-edit .radio label {
margin-right: 10px;
display: block;
float: left;
text-align: left;
width: 200px !important;
}
.front-end-edit .readonly {
border: none !important;
color: #666;
}
.front-end-edit #editor-xtd-buttons {
height: 50px;
width: 600px;
float: left;
}
.front-end-edit .toggle-editor {
height: 50px;
width: 120px;
float: right;
}
#jform_rules-lbl {
display: none;
}
#access-rules a:hover {
background: #f5f5f5 url('../images/slider_minus.png') right top
no-repeat;
color: #444;
}
</style>
<div class="empresa-edit front-end-edit">
<form id="form-cargar" action="<?php echo JRoute::_('index.php?option=com_empresa&task=cargamasiva.mostrar'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
<div class="control-group">
<legend><?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_TITULO_EMPLEADOS'); ?> </legend>
<div class="control-label"><?php echo $this->form->getLabel('seleccione'); ?></div>
<div class="controls"><?php echo $this->form->getInput('seleccione'); ?></div>
</div>
<div class="fltlft" <?php if (!JFactory::getUser()->authorise('core.admin','empresa')): ?> style="display:none;" <?php endif; ?> >
<?php echo JHtml::_('sliders.start', 'permissions-sliders-'.$this->item->id, array('useCookie'=>1)); ?>
<?php echo JHtml::_('sliders.panel', JText::_('ACL Configuration'), 'access-rules'); ?>
<fieldset class="panelform">
<?php echo $this->form->getLabel('rules'); ?>
<?php echo $this->form->getInput('rules'); ?>
</fieldset>
<?php echo JHtml::_('sliders.end'); ?>
</div>
<?php if (!JFactory::getUser()->authorise('core.admin','empresa')): ?>
<script type="text/javascript">
jQuery.noConflict();
jQuery('.tab-pane select').each(function(){
var option_selected = jQuery(this).find(':selected');
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", jQuery(this).attr('name'));
input.setAttribute("value", option_selected.val());
document.getElementById("form-empresa").appendChild(input);
jQuery(this).attr('disabled',true);
});
</script>
<?php endif; ?>
</form>
<form id="form-empresa" action="<?php echo JRoute::_('index.php?option=com_empresa&task=cargamasiva.save'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
<div>
<button id="jform_btnCargar" class="btn tip" type="button" class="hasTooltip" title="<?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_CARGAR'); ?>">
<i class="icon-checkmark"></i> <span><?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_CARGAR'); ?></span> </button>
</div>
<legend><?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_EMPLEADOS'); ?> </legend>
<div class="empresa-edit front-end-edit-list">
<table class="table table-striped" id="jform_cargamasivaList" name="jform[cargamasivaList]" >
<thead>
<tr>
<th width="1%" class="hidden-phone">
<input type="checkbox" id="chk" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="checkAll();" />
</th>
<th class='left'>
<?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_CEDULA') ?>
</th>
<th class='left'>
<?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_NOMBRE') ?>
</th>
<th class='left'>
<?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_APELLIDO') ?>
</th>
<th class='left'>
<?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_CORREO') ?>
</th>
<th class='left'>
<?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_GENERO') ?>
</th>
<th class='left'>
<?php echo JText::_('COM_EMPRESA_CARGA_MASIVA_FECHA_NACIMIENTO') ?>
</th>
</tr>
</thead>
<tbody id="bodyEmpleados" >
</tbody>
</table>
</div>
<div class="form-actions">
<button type="submit" class="btn validate"><i class="icon-save"></i><span><?php echo JText::_('JPROCESAR'); ?></span></button>
<a class="btn" href=" <?php echo JRoute::_('index.php?option=com_empresa&task=empresa.cancel'); ?>" title="<?php echo JText::_('JCANCEL'); ?>">
<i class="icon-cancel"></i> <?php echo JText::_('JCANCEL'); ?></a>
</div>
</form>
</div>
<script type="text/javascript">
function validarExtension(){
alert("entro");
var archivo = document.getElementById('jform_seleccione').value;
if(archivo!= ""){
extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
if(extension!=".xls"){
alert("El Archivo a cargar debe ser Excel en version 2003 (.xls)");
}else{
var fic = archivo.split('\\');
var nombre=fic[fic.length-1];
}
}else{
alert("No ha cargado ningún archivo");
}
}
function getScript(url,success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState
|| this.readyState == 'loaded'
|| this.readyState == 'complete')) {
done = true;
success();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
getScript('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',function() {
js = jQuery.noConflict();
js(document).ready(function(){
js("#jform_btnCargar").click(function()
{
var archivo = document.getElementById('jform_seleccione').value;
var fic = archivo.split('\\');
var nombre=fic[fic.length-1];
js.ajax({
type:"POST",
url: "index.php?option=com_empresa&task=cargamasiva.mostrar",
data:"nombre="+nombre,
datatype:"application/json",
success: function(data){
alert("entro js");
var objData = jQuery.parseJSON(data);
alert("data"+data);
alert(objData.valores[4]);
if (objData.error == 1){
procesarCarga('jform_cargamasivaList', objData.valores);
alert("salio pa controller");
}
},
error: function(jqXHR, textStatus, errorThrown) {
alert("error ajax");
alert(textStatus);
alert(jqXHR);
alert(errorThrown);
}
});
});
});
});
// getScript('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',function() {
// js = jQuery.noConflict();
// // js(document).ready(function(){
//
// js("#jform_btnCargar").click(function()
// {
// var archivo = document.getElementById('jform_seleccione').value;
// var fic = archivo.split('\\');
// var nombre=fic[fic.length-1];
// validarExtension();
//
// js.ajax({
// type:"POST",
// url: "index.php?option=com_empresa&task=cargamasiva.mostrar",
// data:"nombre="+js("#jform_seleccione").val(),
// datatype:"application/json",
// success: function(data){
// alert("entro js");
// var objData = jQuery.parseJSON(data);
// alert("data"+objData);
// if (objData.error == 1){
// procesarCarga('jform_cargamasivaList', objData.valores);
// }
// },
// error: function(jqXHR, textStatus, errorThrown) {
// alert("error ajax");
// alert(textStatus);
// alert(jqXHR);
// alert(errorThrown);
// }
// });
// });
// // });
//});
function procesarCarga(tableID, valores) {
document.getElementById('bodyEmpleados').innerHTML = "";
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
// var archivo = document.getElementById('jform_seleccione').value;
// var fic = archivo.split('\\');
// var nombre=fic[fic.length-1];
// alert(nombre);
<?php
try {
$filas=file('nombre.txt');
// iniciamos contador y la fila a cero
$i=0;
$numero_fila=0;
// mientras exista una fila
while($filas[$i]!=NULL){
// incremento contador de la fila
$row = $filas[$i+1];
// genero array con por medio del separador "," que es el que tiene el archivo txt
$sql = explode(",",$row);
// incrementamos contador
$i++;
$numero_fila++;
}
} catch (Exception $e) {
echo "mostrar";
}
?>
alert(valores[1]);
alert(valores[2]);
alert(valores[0]);
alert("5");
// var numero = "<?php echo $row[0]; ?>";
//
// var fechaVencimiento = "<?php echo "hola";?>";
// var pais = "<?php echo "hola";?>";
// var idPaisEmision = "<?php echo "-gtr";?>";
var numero = valores[0];
var fechaVencimiento =valores[1];
var pais = valores[2];
var idPaisEmision = valores[3];
var numero = valores[4];
var numero = valores[5];
var idPaisEmision = "holis";
var empleados = '<tr class="row' + (rowCount % 2) + '" ><td class="center hidden-phone"><?php echo JHtml::_('grid.id', '', ''); ?></td><td>'+numero+'</td>'
+'<td>'+fechaVencimiento+'</td><td>'+pais+'</td></tr>'+'</td><td>'+idPaisEmision+'</td></tr>';
document.getElementById('bodyEmpleados').innerHTML = document.getElementById('bodyEmpleados').innerHTML + empleados;
}
</script>
因此管理視圖
我假設你使用的實際代碼沒有所有額外的空間,所以我會冒險猜測,並說你使用$ _POST ['name']而不是$ _FILES [ 'File'] ['name'],但很難說這是不是實際的代碼。上面的 – GDP 2014-09-04 16:24:06