how to trim file path from filename

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

    how to trim file path from filename

    I am uploading a file to the server and at the same time I want to
    place the file name in to a database.

    But for the the file to be effective I need to trim the path from the
    filename and leave just the filename.

    Can anyone suggest how I do this?

    It's all part of a google maps mash up.

    The page can be found here.



    Thanks in advance.

    Andy
  • hakimoun

    #2
    Re: how to trim file path from filename

    On 31 mar, 15:49, andyau <pencilsandpixe lst...@googlema il.comwrote:
    I am uploading a file to the server and at the same time I want to
    place the file name in to a database.
    >
    But for the the file to be effective I need to trim the path from the
    filename and leave just the filename.
    >
    Can anyone suggest how I do this?
    >
    It's all part of a google maps mash up.
    >
    The page can be found here.
    >

    >
    Thanks in advance.
    >
    Andy
    in what language are you doing the job on the server side ?
    if you do that with php the file name is in $_FILES['file']
    ['name'] ... I think


    Comment

    • Henry

      #3
      Re: how to trim file path from filename

      On Mar 31, 5:08 pm, Tom Cole wrote:
      <snip>
      I don't think PHP filesystem functions has a method to return
      filepath separators (for example java does...)
      <snip>

      But the Java method returns the file path separator in the environment
      where the JVM is executing, so probably a server where we are
      concerned, but the file path originates from the browser client and so
      its separator may be tied client's OS.

      Comment

      • Tom Cole

        #4
        Re: how to trim file path from filename

        On Mar 31, 12:37 pm, Henry <rcornf...@rain drop.co.ukwrote :
        On Mar 31, 5:08 pm, Tom Cole wrote:
        <snip>I don't think PHP filesystem functions has a method to return
        filepath separators (for example java does...)
        >
        <snip>
        >
        But the Java method returns the file path separator in the environment
        where the JVM is executing, so probably a server where we are
        concerned, but the file path originates from the browser client and so
        its separator may be tied client's OS.
        You are correct. Sorry about that.

        I would still recommend using server side code rather than javascript
        on the client for making this split. The package reference by Erwin
        Moller above would be how I would probably proceed with something like
        this.

        Comment

        • Bart Van der Donck

          #5
          Re: how to trim file path from filename

          Tom Cole wrote:
          I would still recommend using server side code rather than javascript
          on the client for making this split. The package reference by Erwin
          Moller above would be how I would probably proceed with something like
          this.
          Me too. And it is a somewhat uncommon task for (client-side)
          javascript. Normally a server program would parse this kind of data.

          --
          Bart

          Comment

          • Evertjan.

            #6
            Re: how to trim file path from filename

            Bart Van der Donck wrote on 31 mrt 2008 in comp.lang.javas cript:
            Tom Cole wrote:
            >
            >I would still recommend using server side code rather than javascript
            >on the client for making this split. The package reference by Erwin
            >Moller above would be how I would probably proceed with something like
            >this.
            >
            Me too. And it is a somewhat uncommon task for (client-side)
            javascript. Normally a server program would parse this kind of data.
            Indeed, but that can be done using serverside javascript
            as requested and on topic:

            <% // javascript

            var url = 'http://aa.xx/bb/cc/dd.html';

            var temp = url.split('/');
            var file = temp.pop();
            temp.push('');
            var path = temp.join('/');

            %>


            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • Bart Van der Donck

              #7
              Re: how to trim file path from filename

              "Evertjan." wrote:
              Bart Van der Donck wrote:
              >And it is a somewhat uncommon task for (client-side) javascript.
              >Normally a server program would parse this kind of data.
              >
              Indeed, but that can be done using serverside javascript
              as requested and on topic:
              >
              <%    // javascript
              >
              var url = 'http://aa.xx/bb/cc/dd.html';
              >
              var temp = url.split('/');
              var file = temp.pop();
              temp.push('');
              var path = temp.join('/');
              >
              %>
              For an URI, yes. But the specifications of a system path are
              considerably different (and OS-dependent):


              http://en.wikipedia.org/wiki/Path_(computing)

              Cheers,

              --
              Bart

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: how to trim file path from filename

                Bart Van der Donck wrote:
                The traditional directory separator is regular slash ('/'), but Winoid
                systems generally use backslash ('\'). But a file or directory name in
                UNIX may contain backslash as well.
                That appears not to apply to all Unices:

                $ touch '1/2'
                touch: cannot touch `1/2': No such file or directory
                $ touch '1\/2'
                touch: cannot touch `1\\/2': No such file or directory
                $ mkdir '1/2'
                mkdir: cannot create directory `1/2': No such file or directory
                $ mkdir '1\/2'
                mkdir: cannot create directory `1\\/2': No such file or directory
                $ uname -a
                Linux pointedears 2.6.17.13-20060915.184752 +0200 #1 PREEMPT Fri Sep 15
                19:07:16 CEST 2006 i686 GNU/Linux


                PointedEars
                --
                realism: HTML 4.01 Strict
                evangelism: XHTML 1.0 Strict
                madness: XHTML 1.1 as application/xhtml+xml
                -- Bjoern Hoehrmann

                Comment

                • Bart Van der Donck

                  #9
                  Re: how to trim file path from filename

                  Thomas 'PointedEars' Lahn wrote:
                  Bart Van der Donck wrote:
                  >
                  >But a file or directory name in
                  >UNIX may contain backslash as well.
                  >
                  That appears not to apply to all Unices:
                  >
                  $ touch '1/2'
                  touch: cannot touch `1/2': No such file or directory
                  $ touch '1\/2'
                  touch: cannot touch `1\\/2': No such file or directory
                  $ mkdir '1/2'
                  mkdir: cannot create directory `1/2': No such file or directory
                  $ mkdir '1\/2'
                  mkdir: cannot create directory `1\\/2': No such file or directory
                  $ uname -a
                  Linux pointedears 2.6.17.13-20060915.184752 +0200 #1 PREEMPT Fri Sep 15
                  19:07:16 CEST 2006 i686 GNU/Linux
                  Your test only indicates that UNIX filenames cannot contain forward
                  slash. This is logical, because that character is reserved as
                  directory separator. I don't see any problems with backslash here:

                  %ls -l
                  %touch '1\2'
                  %ls -l
                  total 0
                  -rw-r--r-- 1 bart users 0 Apr 3 10:21 1\2
                  %uname -smr
                  FreeBSD 4.8-STABLE i386
                  %

                  Backslash handling might depend on the shell:

                  %echo $SHELL
                  /bin/csh
                  %

                  --
                  Bart

                  Comment

                  Working...