PHP - Probremas con PHPexcel en un servidor privado

 
Vista:

Probremas con PHPexcel en un servidor privado

Publicado por Daniel (2 intervenciones) el 10/07/2016 08:42:47
ayuda
Hice un pequeño script en php en el cual se lee y genera un archivo Excel, y lo guarda en una base de datos, en mi servidor local funciona muy bien pero a la hora de subirlo en un servidor privado se sube el archivo Excel pero ya no lo lee y no guarda los datos porque no puede abrir el archivo, igual me pasa con la descarga no genera el código php para poder crear el archivo Excel.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de kip
Val: 2.325
Plata
Ha disminuido 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

Probremas con PHPexcel en un servidor privado

Publicado por kip (877 intervenciones) el 10/07/2016 17:36:44
Hola, podrias colocar e codigo que te da problemas en el servidor a ver si el error se encuentra alli?

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Probremas con PHPexcel en un servidor privado

Publicado por Daniel (2 intervenciones) el 12/07/2016 02:04:08
Saludos Kip
adjunto el código

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
$fecha = date("j")."/".date("n")."/".date("Y");
    $hora = date("G").":".date("i")." hr.";
 
    $usuario = $_SESSION['dpi'];
    $nombreU = $_SESSION['nombre'].' '.$_SESSION['apellido'];
    extract($_POST);
 
 
    @$action = $_POST['action'];
    if ($action == "upload") {
        //cargamos el archivo al servidor con el mismo nombre
        //solo le agregue el sufijo bak_
        $archivo = $_FILES['excel']['name'];
        $tipo = $_FILES['excel']['type'];
        $destino = "bak_" . $archivo;
        if (copy($_FILES['excel']['tmp_name'], $destino)){
            echo "<p style='margin:10px; color: Green; display:block;'> - Archivo Cargado Con Éxito</p>";
        }
        else{
            echo "<p style='margin:10px; color: Red; display:block;'> - Error Al Cargar el Archivo</p>";
        }
 
 
        if (file_exists("bak_".$archivo)) {
            /** Clases necesarias */
            require_once('Classes/PHPExcel.php');
            require_once('Classes/PHPExcel/Reader/Excel2007.php');
 
            // Cargando la hoja de cálculo
            $objReader = new PHPExcel_Reader_Excel2007();
            $objPHPExcel = $objReader->load("bak_".$archivo);
            $objFecha = new PHPExcel_Shared_Date();
            // Asignar hoja de excel activa
            $objPHPExcel->setActiveSheetIndex(0);
 
 
            //Obtener el numero de filas del archivo
            $numRows = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
 
 
            // Llenamos el arreglo con los datos  del archivo xlsx
            for ($i = 2; $i <= $numRows; $i++) {
                $_DATOS_EXCEL[$i]['orden'] = $objPHPExcel->getActiveSheet()->getCell('A' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['tipo_o'] = $objPHPExcel->getActiveSheet()->getCell('B' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['tipo_i'] = $objPHPExcel->getActiveSheet()->getCell('C' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['etapa'] = $objPHPExcel->getActiveSheet()->getCell('D' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['virtual'] = $objPHPExcel->getActiveSheet()->getCell('E' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['cliente'] = $objPHPExcel->getActiveSheet()->getCell('F' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['con1'] = $objPHPExcel->getActiveSheet()->getCell('G' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['con2'] = $objPHPExcel->getActiveSheet()->getCell('H' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['con3'] = $objPHPExcel->getActiveSheet()->getCell('I' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['direccion'] = $objPHPExcel->getActiveSheet()->getCell('J' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['ref'] = $objPHPExcel->getActiveSheet()->getCell('K' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['red_s'] = $objPHPExcel->getActiveSheet()->getCell('L' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['cd'] = $objPHPExcel->getActiveSheet()->getCell('M' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['cb'] = $objPHPExcel->getActiveSheet()->getCell('N' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['pp'] = $objPHPExcel->getActiveSheet()->getCell('O' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['ct'] = $objPHPExcel->getActiveSheet()->getCell('P' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['ps'] = $objPHPExcel->getActiveSheet()->getCell('Q' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['puentista'] = $objPHPExcel->getActiveSheet()->getCell('R' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['distancia'] = $objPHPExcel->getActiveSheet()->getCell('S' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['centro'] = $objPHPExcel->getActiveSheet()->getCell('T' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['central'] = $objPHPExcel->getActiveSheet()->getCell('U' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['tecnico'] = $objPHPExcel->getActiveSheet()->getCell('V' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['comentario'] = $objPHPExcel->getActiveSheet()->getCell('W' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['clase'] = $objPHPExcel->getActiveSheet()->getCell('X' . $i)->getCalculatedValue();
            }
        }
        //si por algo no cargo el archivo bak_ 
        else {
            echo "<p style='margin:10px; color: Red; display:block;'> - Necesitas primero importar el archivo</p>";
        }
        $errores = 0;
        //recorremos el arreglo multidimensional 
        //para ir recuperando los datos obtenidos
        //del excel e ir insertandolos en la BD
$n = 0;
$campo = 0;
$No = 0;
 
echo "
<center> <strong>".$fecha." &nbsp; ".$hora."</strong> <br/> <p>Personal: ".$nombreU."</p></center>

<div class='contenedor-tabla-importar'>
<table id='tabla-vista-importar-orden'>
    <tr>
        <th>No</th>
        <th>orden</th>
        <th>tipo<br/>orden</th>
        <th>tipo<br/>instalación</th>
        <th>etapa</th>
        <th>virtual</th>
        <th>cliente</th>
        <th>tel</th>
        <th>tel</th>
        <th>tel</th>
        <th>dirección</th>
        <th>referencia</th>
        <th>red<br/>sugerida</th>
        <th>cd</th>
        <th>cb</th>
        <th>pp</th>
        <th>c/t</th>
        <th>ps</th>
        <th>puentista</th>
        <th>distancia</th>
        <th>centro</th>
        <th>central</th>
        <th>técnico</th>
        <th>comentario</th>
        <th>clase orden</th>
    </tr>
";
 
for ($n=2; $n <= $numRows; $n++) {
    $No += 1;
    if (!$_DATOS_EXCEL[$n]['orden'] == 0 && !$_DATOS_EXCEL[$n]['orden'] == Null)
    {
        $campo +=1;
 
    echo
    <tr>
        <td>".$No."</td>
        <td>".$_DATOS_EXCEL[$n]['orden']."</td>
        <td>".$_DATOS_EXCEL[$n]['tipo_o']."</td>
        <td>".$_DATOS_EXCEL[$n]['tipo_i']."</td>
        <td>".$_DATOS_EXCEL[$n]['etapa']."</td>
        <td>".$_DATOS_EXCEL[$n]['virtual']."</td>
        <td>".$_DATOS_EXCEL[$n]['cliente']."</td>
        <td>".$_DATOS_EXCEL[$n]['con1']."</td>
        <td>".$_DATOS_EXCEL[$n]['con2']."</td>
        <td>".$_DATOS_EXCEL[$n]['con3']."</td>
        <td>".$_DATOS_EXCEL[$n]['direccion']."</td>
        <td>".$_DATOS_EXCEL[$n]['ref']."</td>
        <td>".$_DATOS_EXCEL[$n]['red_s']."</td>
        <td>".$_DATOS_EXCEL[$n]['cd']."</td>
        <td>".$_DATOS_EXCEL[$n]['cb']."</td>
        <td>".$_DATOS_EXCEL[$n]['pp']."</td>
        <td>".$_DATOS_EXCEL[$n]['ct']."</td>
        <td>".$_DATOS_EXCEL[$n]['ps']."</td>
        <td>".$_DATOS_EXCEL[$n]['puentista']."</td>
        <td>".$_DATOS_EXCEL[$n]['distancia']."</td>
        <td>".$_DATOS_EXCEL[$n]['centro']."</td>
        <td>".$_DATOS_EXCEL[$n]['central']."</td>
        <td>".$_DATOS_EXCEL[$n]['tecnico']."</td>
        <td>".$_DATOS_EXCEL[$n]['comentario']."</td>
        <td>".$_DATOS_EXCEL[$n]['clase']."</td>
    </tr>";

    //Insertar las ordenes en la base de datos//
    ////////////////////////////////////////////

//Comprobar que la ORDEN ingresada no exista en la DB
$conOrden = 0;
$consulta = mysql_query("SELECT orden From logorden ;",$conexion) or die("No se puedo estableser la conexion con la DB ".mysql_error());
    while ($fila1 = mysql_fetch_array($consulta)) {
        if ($fila1['orden'] == $_DATOS_EXCEL[$n]['orden']) {
            //La orden ya existe
            $conOrden = 1;
        }
        else {

        }
    }

///////////////////////////////////////////////////
if ($conOrden == 0) {

$a = 0;
//$sql = "INSERT INTO datos (nombre,apellido) VALUES ('".$_DATOS_EXCEL[$n]['nombre']."', '".$_DATOS_EXCEL[$n]['direccion']."');";

//Insertar la nueva orden en la tabla LOGORDEN
$sql1 = "INSERT INTO logorden
    (orden, tipo_o, tipo_i, etapa, virtual, cliente, con1, con2, con3, direccion, ref, red_s, cd, cb, pp, ct, ps, asigno, puentista, distancia, centro, central, tecnico, comentario, dia, mes, ano, hora, clase)
    VALUES
    ('".$_DATOS_EXCEL[$n]['orden']."','".$_DATOS_EXCEL[$n]['tipo_o']."','".$_DATOS_EXCEL[$n]['tipo_i']."','".$_DATOS_EXCEL[$n]['etapa']."','".$_DATOS_EXCEL[$n]['virtual']."','".$_DATOS_EXCEL[$n]['cliente']."','".$_DATOS_EXCEL[$n]['con1']."','".$_DATOS_EXCEL[$n]['con2']."','".$_DATOS_EXCEL[$n]['con3']."','".$_DATOS_EXCEL[$n]['direccion']."','".$_DATOS_EXCEL[$n]['ref']."','".$_DATOS_EXCEL[$n]['red_s']."','".$_DATOS_EXCEL[$n]['cd']."','".$_DATOS_EXCEL[$n]['cb']."','".$_DATOS_EXCEL[$n]['pp']."','".$_DATOS_EXCEL[$n]['ct']."','".$_DATOS_EXCEL[$n]['ps']."','".$_SESSION['dpi']."','".$_DATOS_EXCEL[$n]['puentista']."','".$_DATOS_EXCEL[$n]['distancia']."','".$_DATOS_EXCEL[$n]['centro']."','".$_DATOS_EXCEL[$n]['central']."','".$_DATOS_EXCEL[$n]['tecnico']."','".$_DATOS_EXCEL[$n]['comentario']."','".date("j")."','".date("n")."','".date("Y")."','".date("G").":".date("i")."','".$_DATOS_EXCEL[$n]['clase']."');";

//Insertar la orden en la tabla ORDEN
$sql2 = "INSERT INTO orden (orden, virtual, tipo_o, dpi, clase, a)
    VALUES
    ('".$_DATOS_EXCEL[$n]['orden']."','".$_DATOS_EXCEL[$n]['virtual']."','".$_DATOS_EXCEL[$n]['tipo_o']."','".$_DATOS_EXCEL[$n]['tecnico']."','".$_DATOS_EXCEL[$n]['clase']."','".$a."');";

            $resultado1 = mysql_query($sql1,$conexion);
            $resultado2 = mysql_query($sql2,$conexion);

            if (!$resultado1 || !$resultado2) {
                echo "Error al insertar registro " . $campo;
                $errores+=1;
                $campo -=1;
            }



            $con = mysql_query("SELECT * From usuarios WHERE dpi = '".$_DATOS_EXCEL[$n]['tecnico']."';",$conexion) or die("No se puedo estableser la conexion con la DB ".mysql_error());
            while ($row = mysql_fetch_array($con)) {
               $nomT = $row['nombre']." ".$row['apellido'];
               $correo = $row['correo'];
            }
 
//Enviar E-mail
//Preparar el mensaje
    $para = $correo;
    $asunto = "Nueva Orden: ".$_DATOS_EXCEL[$n]['orden'];
    $cabecera = "De: App Delta";
    $message = '<div style="width:100%">
 <laber style=" color: #c9c9c9;">  '.$fecha.' - '.$hora.' </label>
<h1 align="center">Orden '.$_DATOS_EXCEL[$n]['orden'].'</h1>
<p style="padding: 10px;">'.$nomT.', se te ha asignado una nueva orden, por favor revisar tu cuenta para obtener mayor información de la orden asignada en <strong>josueym.com</strong></p>
 </div>';
 
    //Para que el servidor no lo tome como span
    $headers = "MINE-Version:1.0;\r\n";
    $headers .= "Content-type: text/html; \r\n charset=utf-8 \r\n";
    $headers .= "From: App Delta \r\n";
    $headers .= "To: ".$para."; \r\n Subject: ".$asunto." \r\n";
 
 
        if(mail ($para,$asunto, $message, $headers)) {
 
        } else {
            header('location: nuevaOrden.php?error=2');
        }
 
}
else {
    #Ya existe la ORDEN
    #no hacer nada
}
 
    }
 
/////////
}
echo "</table></div>";
 
        echo "<br/><strong><center>ARCHIVO IMPORTADO CON EXITO, EN TOTAL <strong style='color:Green;'>$campo REGISTROS</strong> Y <strong style='color:Red;'>$errores ERRORES</strong></center></strong>";
        //una vez terminado el proceso borramos el archivo que esta en el servidor el bak_
        unlink($destino);
    }
    echo "<center><a href='principal.php' style='color:#FF5722;'>Regresar a Inicio</a></center>";


En mi servidor local no hay ningun problema, es a la hora de montarlo en Bluehost ya no lee el código.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar