Actualizacion para el script de carga de archivos PHP

Pues actualmente estoy llevando unos proyectos web para una firma de abogados en la cual uno de los principales objetivos es solventar un problema de espacio ocupado por un montón de documentos apilados. Para solventar esto un sistema de almacenaje y clasificación es necesario.  Sin mas aca dejo el codigo HTML y PHP:

{code type=HTML}

<html>
<meta charset=”UTF-8″>
<body>
<title>Esqueleto de sistema de digitalización</title>
<form action=”sube.php” enctype=”multipart/form-data” method=”post”>

<p>
Nombre del caso:<br>
<input type=”text” name=”nombrec” size=”30″>
</p>

<p>
Observaciones:<br />
<textarea name=”observaciones” cols=”50″ rows=”5″></textarea>
</p>

<p>
Estado del caso:<br/>
<select name=”estado” size=”3″ multiple>

<option value=”Muerto”>Muerto</option>

<option value=”Pendiente”>Pendiente</option>

<option value=”Trabajo en curso”>Trabajo en curso</option>

<option value=”Resuelto”>Resuelto</option>

</select>
</p>

<p>
Seleccion el tipo de caso:<br/>
<select name=”tipoc” size=”3″ multiple>

<option value=”Laboral”>Laboral</option>

<option value=”Penal”>Penal</option>

<option value=”Civil”>Civil</option>

<option value=”Niñor y adolecentes”>Niños y Adolescentes</option>

<option value=”Contencioso”>Contencioso</option>

<option value=”Registro Mercantil”>Registro Mercantil</option>

</select>
</p>

<p>
Archivo de digitalización:<br>
<input type=”file” name=”ufile” id=”ufile” size=”40″><br/>
<input type=”submit” value=”Subir”><br/>
</p>

</form>
</body>
</html>

{/code}

Ahora el código PHP que hace funcionar el formulario:

{code type=PHP}

<?php
$nombrec=$_POST[‘nombrec’];
$observaciones=$_POST[‘observaciones’];
$estatus=$_POST[‘estado’];
$tipoc=$_POST[‘tipoc’];
$nf=$HTTP_POST_FILES[‘ufile’][‘name’];
$uploaddir = ‘/var/www/carga-de-archivos/ftmp/’;
$uploadfile = $uploaddir . basename($_FILES[‘ufile’][‘name’]);
echo ‘<pre>’;
if (move_uploaded_file($_FILES[‘ufile’][‘tmp_name’], $uploadfile)) {
echo “Archivo cargado al SO.n”;
echo “Insertando el objeto y los datos a la base de datosn”;

$dbh = pg_connect(“host=’127.0.0.1′ port=’5432′ dbname=’BASEDEDATOS’ user=’rafuch0′ password=’NO-REVELADO'”);

if (!$dbh) {
echo “ERROR AL CONECTARn”;
}

pg_exec($dbh, “BEGIN”);
pg_lo_import($database, ‘/tmp/lob.dat’);
$oid2 = pg_lo_import($dbh, “/var/www/carga-de-archivos/ftmp/$nf”);
$sql = “INSERT INTO archivos2 (oid, nombre, observacion, tipo, estatus) VALUES (‘$oid2’, ‘$nombrec’, ‘$observaciones’, ‘$tipoc’, ‘$estatus’)”;
pg_query($dbh, $sql);
pg_exec($dbh, “COMMIT”);
pg_close($dbh);
echo “Inserccion Exitosan”;
echo “<a href=’http://127.0.0.1/carga-de-archivos/index.html’>Cargar otro archivo</a>”;

if (!$oid2) {
echo “ERROR AL IMPORTARn”;
exit;
}
}
else {
echo “Posible Ataquen”;
echo ‘Mas info:’;
print_r($_FILES);
}
print “</pre>”;
?>

{/code}

Este acercamiento es bueno por que deja una copia del archivo en el FS y al mismo tiempo lo exporta como BLOB a la base de datos.  Espero le sirva a alguien y si lo pueden mejorar envíenmelo de regreso para compartirlo con todos. Saludos.

 

6 thoughts on “Actualizacion para el script de carga de archivos PHP”

  1. It’s really a nice and helpful piece of info. I’m satisfied that you shared this useful information with us. Please stay us up to date like this. Thank you for sharing.

    Reply
  2. Hi there exceptional blog! Does running a blog such as this require a massive amount work? I have virtually no knowledge of computer programming but I had been hoping to start my own blog in the near future. Anyways, should you have any suggestions or tips for new blog owners please share. I understand this is off subject but I just wanted to ask. Kudos!

    Reply
    • Hey buddy, thanks for that comment well let me tell you that it does requiere some work and time of your day have a blog.. but if you like to write and share is not a bad idea have your own place to do it, you do have to try to give the best in every article so my advice to you is this … go ahead create your blog and start slow one article at week and little by little put more content into it. And let me know the address of your blog so i can visit you…. se you at the net bye.

      Reply
  3. I know this if off topic but I’m looking into starting my own blog and was curious what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web savvy so I’m not 100% sure. Any tips or advice would be greatly appreciated. Cheers

    Reply

Leave a Reply to wyszukiwarka mp3 Cancel reply