473,788 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

http://www.streetartlocator.com/dev/add_location_3.php

Thanks in advance.

Andy
Mar 31 '08 #1
8 3045
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.

http://www.streetartlocator.com/dev/add_location_3.php

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
Mar 31 '08 #2
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.
Mar 31 '08 #3
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.
Mar 31 '08 #4
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
Mar 31 '08 #5
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)
Mar 31 '08 #6
"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/URI
http://en.wikipedia.org/wiki/Path_(computing)

Cheers,

--
Bart
Mar 31 '08 #7
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
Apr 2 '08 #8
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
Apr 3 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1836
by: Peter A. Schott | last post by:
Got a strange scenario going on here in that I could have sworn this worked yesterday. I am issuing binary retrieval calls to an FTP server, writing to a file, close the file, then removing the file from the remote site. When I do this, I end up with 0 byte files. I was hoping to avoid parsing a list of remote and local files and matching them up that way because it would be easier to remove on successful retrieve. I'm including some...
39
2657
by: Joe Laughlin | last post by:
If I have a character array with "/some/file/directory/file_name", are there any functions / libraries that I could use to separate the directory ("some/file/directory") from the file name ("file_name"). I looked at sscanf(), but that didn't seem to do what I wanted. Thanks, Joe
4
2326
by: moondaddy | last post by:
Using vb.net I need to download image files to the client browser where they can save to disk. Below is some sample code I'm using. when I run this the File Download window in the browser says: File name: ViewAttachment File type: From localhost 1) "ViewAttachment" is the name of the aspx page and not the image file. 2) Its not picking up the file type of jpg. For ContentType I used
1
2765
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp" as the directory. When I use any other hard coded directory or even Server.MapPath() the upload function fails and returns the error: "Exception has been thrown by the target of an invocation." Once I change the root directory to "c:\Temp",...
6
1484
by: Rob | last post by:
I want to copy files from one folder to another... but only if it is a ".txt" file... Below should work, but how would you filter on ".txt" files only ? Thanks ! Dim fileEntries As String() = Directory.GetFiles(targetDirectory) ' Process the list of files found in the directory. Dim fileName As String
7
2087
by: Hitesh | last post by:
Hi, I have a small script here that goes to inside dir and sorts the file by create date. I can return the create date but I don't know how to find the name of that file... I need file that is not latest but was created before the last file. Any hints... I am newbiw python dude and still trying to figure out lot of 'stuff'..
6
11620
by: garyusenet | last post by:
Hi i would like to trim a text string. I have a text string called filename I want to display just the file in my label, and not the path. Can someone tell me how I get everything AFTER, the LAST, BACKSLASH in the string please? Thankyou
5
3138
by: Krustov | last post by:
I have the following list of image files . When searching the latest (numbered file) in this particular case its background_4.*** and its a .jpg file - but - the latest file in the list could also be a .gif file at times . zimages_background/background_1.jpg zimages_background/background_2.jpg zimages_background/background_3.gif zimages_background/background_4.jpg
1
47489
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
10173
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.