close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Change the contents of the Insert in an input file

Thread began 12/12/2018 8:33 am by María Luisa | Last modified 12/26/2018 12:18 pm by María Luisa | 311 views | 2 replies

María Luisa

Change the contents of the Insert in an input file

Change the contents of the Insert in an input file
I have this form to upload and, also, write in the database:

<form  action="" method="post" name="form1" id="form1" enctype="multipart/form-data">

     <table width="100%" align="center" cellpadding="6" cellspacing="6">
      <tr valign="baseline">
       <td width="50%" align="right" valign="top"  class="8px_relleno"><span class="TGral_Der_peq">Tipo de documento / File type</span>:</td>
       <td width="50%" align="left" valign="top" class="8px_relleno"><select name="doc_tipo">
        <option value="TC" <?php if (!(strcmp("TC"""))) {echo "SELECTED";} ?>>Dato 1 / Dato 1</option>
        <option value="CE" <?php if (!(strcmp("CE"""))) {echo "SELECTED";} ?>>Dato 2 / Dato 2</option>
        <option value="RR" <?php if (!(strcmp("RR"""))) {echo "SELECTED";} ?>>Dato 3 / Dato 3</option>
    <tr valign="baseline">
     <td width="50%" align="right" valign="top"  class="8px_relleno"><span class="TGral_Der_peq">Éste es su nombre de usuario PML / This is your PML username:</span></td>
     <td width="50%" align="left" valign="top" class="8px_relleno"><input name="us_nombre" type="text" value="<?php echo $_SESSION['NombreProv']; ?>" size="32" readonly style="background-color:#E0EAE2;" /></td>
   <tr valign="baseline">
     <td width="50%" align="right" valign="top"  class="8px_relleno"><span class="TGral_Der_peq">Seleccione su documento / Choose your file:</span></td>
     <td width="50%" align="left" valign="top" class="8px_relleno">
      <input type="file" name="nombreorig_doc" id="nombreorig_doc" value="" size="32" required /></td>
    <tr valign="baseline">
     <td width="50%" align="right" valign="top"  class="8px_relleno"><span class="TGral_Der_peq">Describa o comente brevemente su asunto (Máximo 250 caracteres)<br />
      Describe or briefly comment the subject (Max. 250 characters):</span></td>
    <td width="50%" align="left" valign="top" class="8px_relleno"><textarea name="doc_asunto" id="doc_asunto" cols="45" required></textarea>
      <td align="right" valign="top">
    <span class="TGral_Der_peq">Fecha</span>
    <td align="left" class="8px_relleno">
    <input name="fecha" type="text" id="fecha" value="<?php echo date("Y-m-d"); ?>" size="15" readonly />
  <tr valign="baseline">
   <td width="50%" align="right" valign="top"  class="8px_relleno">&nbsp;</td>
   <td width="50%" align="left" valign="top" class="8px_relleno"><input name="SubirDocBot" type="submit" id="SubirDocBot" value="Subir documento / Upload file" /></td>
<input type="hidden" name="fecha" value="" />

The users use the input file to upload their files. As there are several problems: users do not name their files correctly (they use characters different from those of English when naming their files) and, also, a certain protocol is necessary to name the file adding part of the user's name, date, type of document that goes up and other things, the following script was created that renames the file replacing the "illegal" characters and adding to the name those prefixes that identify the user, etc . I have to clarify that I have not managed to do this with Data Assist or with MySQLi SB:


//SCRIPTS renombrar, subir e insertar
function replace_specials_characters($s) {
$s preg_replace("/á|à|â|ã|ª/","a",$s);
$s preg_replace("/Á|À|Â|Ã/","A",$s);
$s preg_replace("/é|è|ê/","e",$s);
$s preg_replace("/É|È|Ê/","E",$s);
$s preg_replace("/í|ì|î/","i",$s);
$s preg_replace("/Í|Ì|Î/","I",$s);
$s preg_replace("/ó|ò|ô|õ|º/","o",$s);
$s preg_replace("/Ó|Ò|Ô|Õ/","O",$s);
$s preg_replace("/ú|ù|û/","u",$s);
$s preg_replace("/Ú|Ù|Û/","U",$s);
$s str_replace(" ","-",$s);
$s str_replace("ñ","n",$s);
$s str_replace("Ñ","N",$s);

$s preg_replace('/[^a-zA-Z0-9_.-]/''-'$s);
//Para incluir mensajes de error
$statusMsg '';
$_POST["SubirDocBot"]) && !empty($_FILES["nombreorig_doc"]["name"])){
/*Codigo w3schools*/
$target_dir "../_docs_para_pml/";
$documento $_POST['doc_tipo']; //Establezco variables para incluir en el nuevo nombre del documento subido evitando las repeticiones de nombres
$data date('Y-m-d');
$nombre_usuario $_POST['us_nombre'];
$nombre_extract substr($nombre_usuario,0,7);
//Doy el valor a la variable target_file incluyendo las variables anteriores
$nombreDocumento replace_specials_characters($_FILES["nombreorig_doc"]["name"]);
$target_file $target_dir.$nombre_extract."_".$documento."_".$data."_".basename($nombreDocumento);
$uploadOk 1;
$TipoArchivo pathinfo($target_file,PATHINFO_EXTENSION);
// Comprueba si el archivo existe
if (file_exists($target_file)) {
$statusMsg "Lo sentimos, ese archivo ya existe. Renómbrelo y, por favor, súbalo de nuevo / Sorry, that file already exists. Please rename the file and upload it again.";
$uploadOk 0;
// Comprueba el tamaño del archivo file size
if ($_FILES["nombreorig_doc"]["size"] > 2000000) {
$statusMsg "Lo sentimos, su archivo es demasiado grande. Sólo documentos de menos de 2MB (E2) / Sorry, your file is too large. Please upload documents no larger than 2MB (E2).";
$uploadOk 0;
//Solo ciertos formatos de archivo
if($TipoArchivo != "jpg" && $TipoArchivo != "jpeg" && $TipoArchivo != "doc"
&& $TipoArchivo != "docx" && $TipoArchivo != "pdf" && $TipoArchivo != "xlsx" &&  $TipoArchivo != "xls" &&  $TipoArchivo != "zip" &&  $TipoArchivo != "rar") {
$statusMsg "Lo sentimos solo son permitidos archivos jpg, jpeg, doc, docx, xls,  xlsx, zip o rar (E3). / Sorry, we can only accept the following document types: jpg, jpeg, doc, docx, xls,  xlsx, zip and rar (E3).";
$uploadOk 0;
// Chequea si la variable $uploadOk está a 0 por algún error
if ($uploadOk == 0) {
$statusMsg "Lo sentimos, su archivo no ha sido subido (E4) / Sorry, your file has not been uploaded /E4).";
// si todo va bien se sube el archivo
} else {
    if (
move_uploaded_file($_FILES["nombreorig_doc"]["tmp_name"], $target_file)) {
$statusMsg "El documento / The file  "basename$_FILES["nombreorig_doc"]["name"]). " ha subido correctamente / has been correctly uploaded.";
    } else {
$statusMsg "Lo sentimos, ha sucedido un error en la subida de archivos. Por favor inténtelo de nuevo. (E5) / Sorry, there was an error in the uploading process. Please try again (E5).";

But I want to do the insert in the database with DataAssist

My input file is the following:

<input type="file" name="nombreorig_doc" id="nombreorig_doc" value="" size="32" required />

Next I include the code of the insert:


$InsertQuery = new WA_MySQLi_Query($conexion_i);
$InsertQuery->Action "insert";
$InsertQuery->Table "docs_subidos";
$InsertQuery->bindColumn("doc_tipo""s""".((isset($_POST["doc_tipo"]))?$_POST["doc_tipo"]:"")  ."""WA_BLANK");
$InsertQuery->bindColumn("us_nombre""s""".((isset($_POST["us_nombre"]))?$_POST["us_nombre"]:"")  ."""WA_BLANK");
$InsertQuery->bindColumn("nombreorig_doc""s""".((isset($_FILES["nombreorig_doc"]))?$_FILES["nombreorig_doc"]["name"]:"")  ."""WA_BLANK");
$InsertQuery->bindColumn("doc_asunto""s""".((isset($_POST["doc_asunto"]))?$_POST["doc_asunto"]:"")  ."""WA_BLANK");
$InsertQuery->bindColumn("fecha""s""".((isset($_POST["fecha"]))?$_POST["fecha"]:"")  ."""WA_BLANK");
$InsertGoTo "";
  if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";

But I want that in the column of my table "nombreorig_doc" actually include the variable $ target_file that I defined before to rename the file uploaded by the user.

How can I do it? Can anybody help me?

Thank you

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...