Jump to content


Strip Path


4 replies to this topic

#1 _*Creative Insanity_*

  • Guests

Posted 10 March 2007 - 02:33 PM

I have looked at a heap of upload scripts on here and on alltheweb.com and as yet I have not found a solution.

I have done a upload script for members to upload wav and midi files, but at the moment I am having problems with the files.

What I am trying to do is strip the file path and just keep the name.
At the moment my script adds everything into the database and naturally that is going to cause a broken link when another member goes to preview the wav or midi file.

At the moment C:\blah\blah\sample.wav is being entered into the datanbase and I am trying to remove the c:\blah\blah\ and just have sample.wav edded to the database.
Anyone have any ideas on how to do this?
I have tried temp name, new name, but could not get it to work.

Ta muchly.

#2 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 10 March 2007 - 02:59 PM

Best idea is to explode the file path/name using the slash as the delimiter and grab the last section, e.g...

$explode = explode('\', $file);

$filename = $explode[count($explode)];

Matt

#3 _*Creative Insanity_*

  • Guests

Posted 10 March 2007 - 03:15 PM

Ah huh! Thanks a million Matthew.. now why did this silly old bugger not think of that.
Worked a treat. Thanks heaps.

#4 SecondV

    Young Padawan

  • Members
  • Pip
  • 28 posts
  • Gender:Male
  • Location:Kentucky
  • Interests:All things PHP & MySQL :)

Posted 10 March 2007 - 08:08 PM

... or basename();


// home/user/public_html/basename.php

echo basename(__FILE__); // basename.php


Edited by SecondV, 10 March 2007 - 08:08 PM.


#5 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 10 March 2007 - 09:21 PM

View PostSecondV, on Mar 11 2007, 01:08 AM, said:

... or basename();


// home/user/public_html/basename.php

echo basename(__FILE__); // basename.php

Using that function with windows file structures on a *nix environment is just going to cause a lot of trouble ;)

Having said that using my method with linux structure would cause the same problems.

Matt





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users