Trouble with input type='file'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oxygenearth

    Trouble with input type='file'

    Please who could help me with this...

    I had my structure in Win32, with Apache, PHP, and MySQL, I had a page
    in which I am transfering an image to the database in MySQL using PHP.
    But now I am in Apache/Linux/MySQL(FreeBSD) with the same files.

    My problem is.. when I try to submit the variables to the php file,
    this does not get the binFile, in other words, the
    file($_POST['binFile']) does not pass throug the SUBMIT html
    statemenT, so it is not transferred to the database, i have tried to
    visualize the content of my binFile var, but.. it is EMPTY !!

    I write the code here, for you to HELP ME !! thanks all of you

    open_db.inc:
    <?php
    $hndlr=mysql_co nnect("server.c ioh.org.co", "........",
    "xxxxxxxx") ;
    mysql_select_db ("geobase", $hndlr) or die(mysql_errno () . ": " .
    mysql_error() . "<br>");
    ?>

    add.php:
    <?php

    if ($_POST['action'] == "upload") {
    $action=$_POST['action'];
    $cod=$_POST['cod'];
    //$binFile=$_POST['binFile'];
    // tomemos el dato uploaded e insertemoslo en la base de datos
    ahora
    include "open_db.in c";
    print $action."<br>";
    print $cod."<br>";
    //print "uploading with cod=".strval($c od)." and
    codigo_pto=".st rval($codigo_pt o);
    if (isset($_POST['binFile']) && $_POST['binFile'] != "none") {
    $data = addslashes(frea d(fopen($_POST['binFile'], "r"),
    filesize($_POST['binFile'])));
    echo "<br>Usando Codigo <B>", $cod,"</B>";
    $codigo_pto2 = intval(trim($co d));
    $sql = "INSERT INTO imagen ";
    $sql .= "(cod_pto, imagen) ";
    $sql .= "VALUES ('$codigo_pto2' , '$data')";
    $res=mysql_quer y($sql, $hndlr);
    echo "<BR>El archivo ha sido transferido exitosamente <BR>a la
    Base de Datos GEOBASE.<BR>";
    }
    mysql_close();
    ?>
    <script type="text/javascript">
    window.close()
    </script>
    <?
    } else {
    ?>
    <HTML>
    <BODY>
    <P><font face="Arial Narrow" size="4">Por favor introduzca la imagen
    del punto
    de código <B>
    <? $codigo_pto=$_G ET['codigo_pto'];
    echo $codigo_pto."<- este es el codigo tomado de la URL"; ?>
    </B><BR>
    a ser guardada en la Base de Datos -<b>GEOBASE</b>- residente en el
    servidor MySQL
    </font></P>
    <FORM METHOD="POST" ACTION="add.php " ENCTYPE="multip art/form-data">
    <!--
    <INPUT TYPE="hidden" NAME="MAX_FILE_ SIZE" VALUE="1000000" >
    -->
    <INPUT TYPE="hidden" NAME="action" VALUE="upload">
    <INPUT TYPE="hidden" NAME="cod" VALUE="<? echo $codigo_pto; ?>">
    <TABLE BORDER="1" bordercolor="#0 00000" bgcolor="#4A959 5">
    <TR>
    <TD><font color="#CCCCCC" face="Arial Narrow"><b><fon t
    color="#E5E5E5" >Imagen
    a cargar:</font></b></font> </TD>
    <TD><INPUT TYPE="file" NAME="binFile"> </TD>
    </TR>
    <TR>
    <TD COLSPAN="2"><IN PUT TYPE="submit" VALUE="Cargar"> </TD>
    </TR>
    </TABLE>
    </FORM>
    </BODY>
    </HTML>
    <?php
    }
    ?>
  • Alvaro G. Vicario

    #2
    Re: Trouble with input type='file'

    *** Oxygenearth escribió/wrote (30 Aug 2004 10:04:10 -0700):[color=blue]
    > fopen($_POST['binFile'], "r")[/color]

    The preferred way of handling uploaded files is $_FILES:

    $_FILES['userfile']['name']
    The original name of the file on the client machine.

    $_FILES['userfile']['type']
    The mime type of the file, if the browser provided this information. An
    example would be "image/gif".

    $_FILES['userfile']['size']
    The size, in bytes, of the uploaded file.

    $_FILES['userfile']['tmp_name']
    The temporary filename of the file in which the uploaded file was stored on
    the server.

    $_FILES['userfile']['error']
    The error code associated with this file upload. ['error'] was added in PHP
    4.2.0




    --
    --
    -+ Álvaro G. Vicario - Burgos, Spain - ICQ 46788716
    +- http://www.demogracia.com (la web de humor para mayores de 100 años)
    ++ «Sonríe, que te vamos a hacer una foto para la esquela»
    --

    Comment

    • Oxygenearth

      #3
      Re: Trouble with input type='file'

      Hola alvaro, gracias por tu mensaje

      el $HTTP_POST_FILE S['variable']['name'] me esta guardando el nombre
      del archivo pero no me guarda el contenido en la variable que uso para
      descargar el dato.
      dice que fallo al abrir el stream, no hay tal archivo o directorio...

      que crees que sea-...? GRACIAS

      Warning: fopen(summer200 4_weightlifting .jpg): failed to open stream:
      No such file or directory in /var/scripts/new_php/geodb/add.php on
      line 13

      Warning: fread(): supplied argument is not a valid stream resource in
      /var/scripts/new_php/geodb/add.php on line 13


      "Alvaro G. Vicario" <kAlvaroNOSPAMT HANKS@terra.es> wrote in message

      news:<pwklz3khb j4m$.1fs9hamoeg wct.dlg@40tude. net>...[color=blue]
      > *** Oxygenearth escribió/wrote (30 Aug 2004 10:04:10 -0700):[color=green]
      > > fopen($_POST['binFile'], "r")[/color]
      >
      > The preferred way of handling uploaded files is $_FILES:
      >
      > $_FILES['userfile']['name']
      > The original name of the file on the client machine.
      >
      > $_FILES['userfile']['type']
      > The mime type of the file, if the browser provided this information. An
      > example would be "image/gif".
      >
      > $_FILES['userfile']['size']
      > The size, in bytes, of the uploaded file.
      >
      > $_FILES['userfile']['tmp_name']
      > The temporary filename of the file in which the uploaded file was stored on
      > the server.
      >
      > $_FILES['userfile']['error']
      > The error code associated with this file upload. ['error'] was added in PHP
      > 4.2.0
      >
      >
      >
      >
      > --[/color]

      Comment

      • Alvaro G. Vicario

        #4
        Re: Trouble with input type='file'

        *** Oxygenearth escribió/wrote (2 Sep 2004 13:41:22 -0700):[color=blue]
        > el $HTTP_POST_FILE S['variable']['name'] me esta guardando el nombre
        > del archivo pero no me guarda el contenido en la variable que uso para
        > descargar el dato.[/color]

        $_FILES['userfile']['name']
        The original name of the file on the client machine.

        En español: el nombre original del archivo en el PC *cliente*.


        $_FILES['userfile']['tmp_name']
        The temporary filename of the file in which the uploaded file was stored on
        the server.

        En español: el nombre del archivo temporal en el que se ha guardado en el
        *servidor* el archivo subido.


        --
        --
        -+ Álvaro G. Vicario - Burgos, Spain - ICQ 46788716
        +- http://www.demogracia.com (la web de humor para mayores de 100 años)
        ++ «Sonríe, que te vamos a hacer una foto para la esquela»
        --

        Comment

        Working...