469,303 Members | 1,900 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,303 developers. It's quick & easy.

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.
Jul 23 '05 #1
3 2805
"William Starr Moake" <ws*****@yahoo.com> skrev i en meddelelse
news:dv********************************@4ax.com...
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.


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(path)
{
var pathArray = path.split("/");
return pathArray[pathArray.length-1];
}

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

Kind regards - Jakob
Jul 23 '05 #2
On Wed, 7 Apr 2004 10:03:13 +0200, "Jakob Lund Krarup"
<ne************@jake.dk> wrote:
"William Starr Moake" <ws*****@yahoo.com> skrev i en meddelelse
news:dv********************************@4ax.com.. .
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.


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(path)
{
var pathArray = path.split("/");
return pathArray[pathArray.length-1];
}

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

Kind regards - Jakob

Thanks for trying, but I can't get the script to work.
From file://C:\Windows\Desktop\Images\logo.gif it returns:
C:\Windows\Desktop\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.
Jul 23 '05 #3
Ivo

"William Starr Moake" wrote
"Jakob Lund Krarup" wrote:
"William Starr Moake" skrev
//This function returns only the filename from a string containing a path function getFileName(path)
{
var pathArray = path.split("/");
return pathArray[pathArray.length-1];
}

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

Thanks for trying, but I can't get the script to work.
From file://C:\Windows\Desktop\Images\logo.gif it returns:
C:\Windows\Desktop\Images\logo.gif, simply removing the file://
I tried varying the minus number, but nothing worked.


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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Kevin Vogler | last post: by
10 posts views Thread by mark | r | last post: by
6 posts views Thread by bissatch | last post: by
2 posts views Thread by CK | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.