file upload

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

    file upload

    Hi all, this might be more of an html question but I think it can be done in
    PHP, so I will ask here.

    I have an html form that allows for .pdf file uploads. This script will
    serve two functions 1) upload a .pdf file to a specific directory on the web
    server and 2) create an entry into the db that includes the name of the file
    just uploaded. I want to have another web page that will dynamically list
    all of the names of the files uploaded as clickable hyperlinks so they can
    view those .pdf files.

    I have the file upload code working just fine, but the name that gets
    written to the database as something like: "/tmp/phpTg2toF", which is not
    the name of the file. How can I "get" the name of the file that I upload so
    that it can be written into the db as a file name? Anyone have ideas? Thanks
    in advance. Here is my code:


    <html>
    <head>
    <title>Upload </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <form action="thisfil e.php" method="post" ENCTYPE="multip art/form-data">
    <body bgcolor="#fffff f" text="#000000">

    <?{
    if ($Upload) {
    if (!copy($file, "../TargetDir/$file_name")) {
    echo "Problem uploading .pdf file...please try
    again.<br><br>< br><br><br>";
    exit;
    } else {
    $result = mysql_query("in sert into db values ('$id', '$name')");
    if (!$result) {
    echo "<br><br>Th ere was a problem adding the .pdf - please submit
    later.";
    }?>

    <input type="file" size=40 name="file"><br >

    <input type="hidden" name="MAX_FILE_ SIZE" value="100000">
    <input type="submit" name=Upload value="Upload">
    <?}?>
    </form></body></html>


  • Alvaro G Vicario

    #2
    Re: file upload

    *** Mosher wrote/escribió (Wed, 27 Apr 2005 12:16:49 -0500):[color=blue]
    > How can I "get" the name of the file that I upload so
    > that it can be written into the db as a file name?[/color]

    Sorry, I can't understand your code. But the name of the original file is
    kept in the $_FILES array. View its contents using print_r() and then adapt
    your code.



    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- http://bits.demogracia.com - Mi sitio sobre programación web
    -- Don't e-mail me your questions, post them to the group
    --

    Comment

    • Mosher

      #3
      Re: file upload

      Alvaro, thanks for the info. Can you point me to some information about the
      $_FILES statement? I can't seem to find any info on it.

      Thanks again,

      Mosher

      "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
      message news:57tlbzavc3 0o.jlaqzfcgj5mm $.dlg@40tude.ne t...[color=blue]
      > *** Mosher wrote/escribió (Wed, 27 Apr 2005 12:16:49 -0500):[color=green]
      >> How can I "get" the name of the file that I upload so
      >> that it can be written into the db as a file name?[/color]
      >
      > Sorry, I can't understand your code. But the name of the original file is
      > kept in the $_FILES array. View its contents using print_r() and then
      > adapt
      > your code.
      >
      >
      >
      > --
      > -- Álvaro G. Vicario - Burgos, Spain
      > -- http://bits.demogracia.com - Mi sitio sobre programación web
      > -- Don't e-mail me your questions, post them to the group
      > --[/color]


      Comment

      • Mosher

        #4
        Re: file upload

        Alvaro, thanks so much for the info. I was able to get the original file
        name by using: $HTTP_POST_FILE S['file']['name']

        Mosher

        "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
        message news:57tlbzavc3 0o.jlaqzfcgj5mm $.dlg@40tude.ne t...[color=blue]
        > *** Mosher wrote/escribió (Wed, 27 Apr 2005 12:16:49 -0500):[color=green]
        >> How can I "get" the name of the file that I upload so
        >> that it can be written into the db as a file name?[/color]
        >
        > Sorry, I can't understand your code. But the name of the original file is
        > kept in the $_FILES array. View its contents using print_r() and then
        > adapt
        > your code.
        >
        >
        >
        > --
        > -- Álvaro G. Vicario - Burgos, Spain
        > -- http://bits.demogracia.com - Mi sitio sobre programación web
        > -- Don't e-mail me your questions, post them to the group
        > --[/color]


        Comment

        • Malcolm Dew-Jones

          #5
          Re: file upload

          Mosher (mosh_king@yaho o.com) wrote:
          : Alvaro, thanks for the info. Can you point me to some information about the
          : $_FILES statement? I can't seem to find any info on it.

          That's odd, try google: php $_FILES

          maybe that will have some info on it.


          --

          This space not for rent.

          Comment

          • madmaster

            #6
            Re: file upload

            Hi all.. here is the original manual topic for files upload and thought
            It could be useful.



            Comment

            • MsKitty

              #7
              Re: file upload

              Here is a function I wrote to move an uploaded file to where I want it
              with the original file name which is $_FILES['userfile']['name'] -
              the temp name is $_FILES['userfile']['tmp_name']



              function file_upload(){
              global $ourdir;
              $uploadFile = $ourdir ."/". $_FILES['userfile']['name'];
              if (file_exists($_ FILES['userfile']['tmp_name'])) {

              if (!move_uploaded _file($_FILES['userfile']['tmp_name'],
              $uploadFile))
              {
              print "Problem with file upload - Here's some debugging
              info:\n<pre>";
              print_r($_FILES );
              print "</pre>";
              } else {
              chmod($uploadFi le, 0644);
              }
              }
              }


              Hope this helps (no flames about using an evil global variable please!
              made sense in this app)

              Kitty
              San Diego web design, development, training, and programming - we set up membership sites, Blogs, Ecommerce, Dynamic Content, and easily maintained web sites


              Comment

              Working...