Jump to content

cut part of a string


map200uk

Recommended Posts

hi,

 

i just realised a problem with some of my code:

 

$path (held) in database is a value of the location of the audio file, so for example /bin/apache/htdocs/mp3

 

when i echoe the path it echoes that + file.mp3 which is fine until it comes to trying to link to the file and ti will try

 

http://localhost/bin/apache/htdocs/file.mp3

 

im trying to think of the best way to sort this out, i can see 2 problems, and before anyone says-this is for my use,so i can browse my library from a different pc i.e. laptop downstairs via the network and stream to it...so no copyright issues:)

 

is there any way i can link to a file at this location!?

Link to comment
https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/
Share on other sites

You are not providing enough information. What is the value stored int he db and what is the code you are using to create the path?

 

I think at least part of the problem is that you are using the full path to the file - you should use the relative path from the root of the web site.. So, instead of using /bin/apache/htdocs/mp3/file.mp3 it should be ./mp3/file.mp3

Link to comment
https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244267
Share on other sites

the path is stored in the database is the full path-from when the file tag data is read

 

so scan dir path=dir/to/file/file.mp3 => database

 

then this was echoed out and used for a link,

 

 

would it be better to :

 

a) cut the path before inserted in database

 

i.e. if $PATH=/usr/bin/apache/htdocs/mp3

 

we remove the /usr/bin/apache/htdocs from the path and just store /mp3/file.mp3 ?

 

b) My 2nd problem-how would i make it possible to link to files which are NOT within the apache root dir structure?

 

Link to comment
https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244271
Share on other sites

thinking about it even if i removed the server root from a string, the issue of a dir that isnt within the apache root is still an issue? as it would not know where to look would it?

 

If i passed a url of say http://map.com/testing/blabla/

 

how would ../ work? if i had a file in :

 

/opt/apache/mp3

 

and doc root is /opt/apache/htdocs/

 

is it possible to access the file?

Link to comment
https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244372
Share on other sites

Hi

 

I think what you need to do (as mention previously) is use a symlink

 

This line will create that link

ln -s /opt/apache/htdocs/mp3 /opt/apache/mp3

 

also you may need to give permissions to the folder (this will give read access to all users, including apache)

 

chmod 744 /opt/apache/htdocs/mp3

 

 

and then drop the file path as mentioned somewhere else and just use ./mp3/file.mp3 in the html

 

does that help?

 

Cheers,

tdw

Link to comment
https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244382
Share on other sites

Hmmm, can you not have two different folders for it?

 

Or if it does recurse, then mkdir a directory ...htdocs/mp3/

 

then create the symlinks under that to the various locations

 

so you have

.../htdocs/mp3/marksmp3s => /home/mark/media

.../htdocs/mp3/othersmp3s => /media/vault/mp3

Link to comment
https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244480
Share on other sites

yes, well i cant really see whats going on in your head :)

 

I think your best idea is to set the folder layout / symlinks and permissions. before your php gets there. Dynamically creating links etc (especially to outside your document root) will probably implode on you somehow!

 

cheers,

tdw

Link to comment
https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-245189
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.