473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 3012
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kevin Vogler | last post by:
I have a subdirectory with it's own images folder. All the image paths in the pages in the sub directory are "image/image.jpg" When I Response.Redirect to a page in the subdirectory the images...
10
by: mark | r | last post by:
anyone know a useful way of hiding image paths so images on my site cant be directly linked to? ive seen sites that use <img src="image.asp?/moo/fred/image01.jpg"> (where the path starts from...
6
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a...
7
by: Nilesh | last post by:
I am using background-image attribute in a CSS file and linking the CSS file to aspx page. But strangly, background-image attribute is not working for relative URL. e.g. If I apply following css...
2
by: Han Sen | last post by:
I'm building a treeview from an xml file. The node values point to various paths, some of which are network paths. Next to every node I'd like to display an "offline" image (if that the path is...
4
by: NASAdude | last post by:
I'm working on distributing a database using VS Tools for Office, and am having trouble with linked images on forms/reports. The image objects have a default path\file set on the .Picture property,...
2
by: CK | last post by:
Hello All, I am trying to extend the default asp:ImageButton to include an image for an enabled state and a second image for a disabled state. I currently did this by extending the ImageButton...
6
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
2
by: bizt | last post by:
Hi, Is it possible to obtain the width/ height of an image when that image is dyanically created using a PHP script and passing GET attributes. For example: <img...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.