i´m trying to upload a file using file_get_contents and read it, currently i can read the file and get data, but only with files inside the project folder, can someone tell me, how to do this with a post method or someting?
Here My code:
     <?php    $RE_fecha='.*?((?:2|1)\d{3}(?:-|\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1]))(?:T|\s)(?:(?:[0-1][0-9])|(?:2[0-3])):(?:[0-5][0-9]):(?:[0-5][0-9]))';            $xmlCont=file_get_contents('archivo');  //$xmlCont=file_get_contents($_FILES);    $RE_receptor='<.*?Receptor.*?rfc="(.*?)"';  $RE_nombre='<.*?Receptor.*?nombre="(.*?)"';  $RE_calle='<.*?Receptor.*?calle="(.*?)"';  $RE_cp='<.*?Receptor.*?codigoPostal="(.*?)"';  $RE_colonia='<.*?Receptor.*?colonia="(.*?)"';  $RE_estado='<.*?Receptor.*?estado="(.*?)"';  $RE_municipio='<.*?Receptor.*?municipio="(.*?)"';  $RE_noExterior='<.*?Receptor.*?noExterior="(.*?)"';  $RE_noInterior='<.*?Receptor.*?noInterior="(.*?)"';  $RE_pais='<.*?Receptor.*?pais="(.*?)"';        //Extraer fecha del xml  preg_match_all("/".$RE_fecha."/is",$xmlCont, $matches);  $fechaxmlunix=strtotime($matches[1][0]);  $fechaxmlorig=$matches[1][0];  unset($matches);    //Extraer rfc del receptor  preg_match_all('/'.$RE_receptor.'/is',$xmlCont, $matches);  $rfc=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer rfc del receptor  preg_match_all('/'.$RE_nombre.'/is',$xmlCont, $matches);  $nombre_rs=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer rfc del receptor  preg_match_all('/'.$RE_calle.'/is',$xmlCont, $matches);  $calle=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer código postal del receptor  preg_match_all('/'.$RE_cp.'/is',$xmlCont, $matches);  $cp=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer colonia del receptor  preg_match_all('/'.$RE_colonia.'/is',$xmlCont, $matches);  $colonia=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer estado del receptor  preg_match_all('/'.$RE_estado.'/is',$xmlCont, $matches);  $estado=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer municipio del receptor  preg_match_all('/'.$RE_municipio.'/is',$xmlCont, $matches);  $municipio=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer no. exterior del receptor  preg_match_all('/'.$RE_noExterior.'/is',$xmlCont, $matches);  $no_exterior=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer no. interior del receptor  preg_match_all('/'.$RE_noInterior.'/is',$xmlCont, $matches);  $no_interior=$matches[1][0]; // RFC del receptor  unset($matches);    //Extraer pais del receptor  preg_match_all('/'.$RE_pais.'/is',$xmlCont, $matches);  $pais=$matches[1][0]; // RFC del receptor  unset($matches);    echo "Fecha es: ".$fechaxmlorig."<br />";  echo "Fecha UNIX es: ".$fechaxmlunix."<br />";  echo "RFC receptor es: ".$rfc."<br />";  echo "Nombre: ".$nombre_rs."<br />";  echo "Calle: ".$calle."<br />";  echo "No. Exterior: ".$no_exterior."<br />";  echo "No. Interior: ".$no_interior."<br />";  echo "Colonia: ".$colonia."<br />";  echo "Municipio: ".$municipio."<br />";  echo "Estado: ".$estado."<br />";  echo "País: ".$pais."<br />";  echo "Código Postal: ".$cp."<br />";      // open MySQL connection  $connection = mysqli_connect("localhost", "root", "", "rbp") or die ("ERROR: Cannot connect");    //$sql = "INSERT INTO facturas_xml (rfc, nombre_rs, calle) VALUES ('$rfc', '$desxml', '$calle')";  $sql = "INSERT INTO facturas_xml (rfc, nombre_rs, calle, no_exterior, no_interior, colonia, municipio, estado, pais, cp, nombre) VALUES ('$rfc', '$nombre_rs', '$calle', '$no_exterior', '$no_interior', '$colonia', '$municipio', '$estado', '$pais', '$cp', '$nombre_rs')";  mysqli_query($connection, $sql) or die ("ERROR: " .mysqli_error($connection) . " (query was $sql)");    // close connection  mysqli_close($connection);    require 'view/carga.view.php';    ?>      <html>    <header>          <meta charset="utf-8" />  </header>  <body>  <h2>Carga de archivos </h2>  <?php if(strlen($msj)>0):?>  <div><?php echo $msj; ?></div>  <?php endif;?>  <form action="obtener.php" method="post"   enctype="multipart/form-data">          <input type="file" name="archivo" id="archivo"></input>      <input type="submit" name="subir" value="Subir archivo"></input>  </form>    </body>    </html>     
No comments:
Post a Comment