image file paths

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • William Starr Moake

    #1

    image file paths

    Is there a script to convert image file paths from absolute to just
    img src="imagename. jpg"? This is for an IE-based WYSIWYG editor. The
    doImage execCommand produces an absolute file path, which then must be
    shortened manually before the user uploads the page to his web host.
  • Jakob Lund Krarup

    #2
    Re: image file paths

    "William Starr Moake" <wsmoake@yahoo. com> skrev i en meddelelse
    news:dvl6705336 jgl38dbuu921p62 u3svjh37e@4ax.c om...[color=blue]
    > Is there a script to convert image file paths from absolute to just
    > img src="imagename. jpg"? This is for an IE-based WYSIWYG editor. The
    > doImage execCommand produces an absolute file path, which then must be
    > shortened manually before the user uploads the page to his web host.[/color]

    Hi William
    The path to the file will usually be interspersed with "/" or "\" signs to
    show where the different folders are in the path.
    E.g.: "graphics/myItems/image.gif"
    You can split that URL using the String objects split() method, and then use
    the last element in the resulting array:


    //This function returns only the filename from a string containing a path
    function getFileName(pat h)
    {
    var pathArray = path.split("/");
    return pathArray[pathArray.lengt h-1];
    }

    Try it out at: http://www.jake.dk/programmering/javascript/forWilliam

    Kind regards - Jakob


    Comment

    • William Starr Moake

      #3
      Re: image file paths

      On Wed, 7 Apr 2004 10:03:13 +0200, "Jakob Lund Krarup"
      <news-removeme-@jake.dk> wrote:
      [color=blue]
      >"William Starr Moake" <wsmoake@yahoo. com> skrev i en meddelelse
      >news:dvl670533 6jgl38dbuu921p6 2u3svjh37e@4ax. com...[color=green]
      >> Is there a script to convert image file paths from absolute to just
      >> img src="imagename. jpg"? This is for an IE-based WYSIWYG editor. The
      >> doImage execCommand produces an absolute file path, which then must be
      >> shortened manually before the user uploads the page to his web host.[/color]
      >
      >Hi William
      >The path to the file will usually be interspersed with "/" or "\" signs to
      >show where the different folders are in the path.
      >E.g.: "graphics/myItems/image.gif"
      >You can split that URL using the String objects split() method, and then use
      >the last element in the resulting array:
      >
      >
      > //This function returns only the filename from a string containing a path
      > function getFileName(pat h)
      > {
      > var pathArray = path.split("/");
      > return pathArray[pathArray.lengt h-1];
      > }
      >
      >Try it out at: http://www.jake.dk/programmering/javascript/forWilliam
      >
      >Kind regards - Jakob
      >[/color]
      Thanks for trying, but I can't get the script to work.
      From file://C:\Windows\Desk top\Images\logo .gif it returns:
      C:\Windows\Desk top\Images\logo .gif, simply removing the file://
      I tried varying the minus number, but nothing worked.
      I need a script that will return img src="logo.gif" to be placed in
      the page source code when an image is inserted. The IE doImage
      function by itself returns the full image path, which is a nightmare
      to deal with for the user of a WYSIWYG editor.

      Comment

      • Ivo

        #4
        Re: image file paths


        "William Starr Moake" wrote[color=blue]
        > "Jakob Lund Krarup" wrote:[color=green]
        > >"William Starr Moake" skrev
        > > //This function returns only the filename from a string containing a[/color][/color]
        path[color=blue][color=green]
        > > function getFileName(pat h)
        > > {
        > > var pathArray = path.split("/");
        > > return pathArray[pathArray.lengt h-1];
        > > }
        > >
        > >Try it out at: http://www.jake.dk/programmering/javascript/forWilliam
        > >[/color]
        > Thanks for trying, but I can't get the script to work.
        > From file://C:\Windows\Desk top\Images\logo .gif it returns:
        > C:\Windows\Desk top\Images\logo .gif, simply removing the file://
        > I tried varying the minus number, but nothing worked.[/color]

        Which number? The reason you're seeing this behaviour is because clearly the
        function as present splits on slashes alone. If you change it to
        var pathArray = path.split(/[\\\/]/);
        it will split on slashes and backslashes. Or convert the MS Windows
        backslashes to normal slashes first.
        HTH
        Ivo


        Comment

        Working...