map200uk Posted May 3, 2007 Share Posted May 3, 2007 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 More sharing options...
map200uk Posted May 3, 2007 Author Share Posted May 3, 2007 i think im missing something:| Link to comment https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244259 Share on other sites More sharing options...
Psycho Posted May 3, 2007 Share Posted May 3, 2007 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 More sharing options...
map200uk Posted May 3, 2007 Author Share Posted May 3, 2007 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 More sharing options...
effigy Posted May 3, 2007 Share Posted May 3, 2007 How about something like this? <pre> <?php echo str_replace($_SERVER['DOCUMENT_ROOT'], '', $dir); ?> </pre> b) My 2nd problem-how would i make it possible to link to files which are NOT within the apache root dir structure? Use ../ or symbolic links. Link to comment https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244344 Share on other sites More sharing options...
map200uk Posted May 3, 2007 Author Share Posted May 3, 2007 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 More sharing options...
thedarkwinter Posted May 3, 2007 Share Posted May 3, 2007 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 More sharing options...
map200uk Posted May 3, 2007 Author Share Posted May 3, 2007 it does mate, but i think i hve a bit more of a problem.. it scans the directories recurisvely so we could have 2 directories /home/mark/media and /media/vault/mp3 both of which would need to have a sym link created after the scan? Link to comment https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244473 Share on other sites More sharing options...
thedarkwinter Posted May 3, 2007 Share Posted May 3, 2007 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 More sharing options...
map200uk Posted May 3, 2007 Author Share Posted May 3, 2007 hmm yea, im gonna have to think this over, didnt think this through before beginning to code it! perhaps when if is_dir, then create a symlink? Link to comment https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244481 Share on other sites More sharing options...
map200uk Posted May 3, 2007 Author Share Posted May 3, 2007 only way i can see of doing this involves using exec? and sudoers (i think sudoers is needed)! Link to comment https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-244548 Share on other sites More sharing options...
thedarkwinter Posted May 4, 2007 Share Posted May 4, 2007 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 More sharing options...
map200uk Posted May 4, 2007 Author Share Posted May 4, 2007 thing is mate, i cant can i? as it scans the directories, they arent manually added! Link to comment https://forums.phpfreaks.com/topic/49797-cut-part-of-a-string/#findComment-245321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.