Pjack125 Posted December 11, 2008 Share Posted December 11, 2008 This maybe simple but I can't find the solution anywhere. I am creating a GUI that links to files stored on a network drive. I am using the <input type="file"> tag so the user can browse to where the file is then save that information to a database. The Issue that arises is that when the file information is stored only the name is stored but not where the user got the file from. for example: lets say i wanted to store the location of hot_blooded.mp3. I want it to store C:\windows\My documents\My music\hot_blooded.mp3 instead of just hot_blooded.mp3 Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/ Share on other sites More sharing options...
Mark Baker Posted December 11, 2008 Share Posted December 11, 2008 Any particular reason why? All the uploader has to do is delete the original file from their local disk after they've uploaded it, and your database will be out of date Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712458 Share on other sites More sharing options...
Pjack125 Posted December 11, 2008 Author Share Posted December 11, 2008 I am not trying to upload the file. I just want to record the location of the file (the complete path) on the network drive. I just thought it would be nice to use the browse function instead of the person manually typing the full path in a regular text field. and yes i know that will make the db out of date but that is what the users want. Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712465 Share on other sites More sharing options...
redarrow Posted December 11, 2008 Share Posted December 11, 2008 <?php echo $_SERVER['DOCUMENT_ROOT']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712469 Share on other sites More sharing options...
Pjack125 Posted December 11, 2008 Author Share Posted December 11, 2008 I am trying to get a local path information is there no way for me to get the full path info to show the path from a local machine example C:\windows\My documents\My music\ or something similar. I tried using echo $_SERVER['DOCUMENT_ROOT']; it just displayed the word array... Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712495 Share on other sites More sharing options...
Pjack125 Posted December 11, 2008 Author Share Posted December 11, 2008 I found a way to do it with pathinfo(); except now i am have the following issues [*]I have multiples files being uploaded how would i do this without haveing to write $path_partsIMG = pathinfo($_POST['ProgImg1']); $_SESSION['IMG1'] = $path_partsIMG['dirname'].$path_partsIMG['basename']; $path_partsIMG2 = pathinfo($_POST['ProgImg2']); $_SESSION['IMG2'] = $path_partsIMG2['dirname'].$path_partsIMG2['basename']; // and so on My coding skills are limited so i am scratching head trying to turn it into a function that i wont have redundant lines of code The result is not what I expected. I got an output of .Q:\\Engineering Web\\Test\\images\\Freescale_logo.jpg as you can see there is an annoying '.' and '\\' where there isn't suppose to be one Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712536 Share on other sites More sharing options...
gevans Posted December 11, 2008 Share Posted December 11, 2008 Just to help me understand this, please tell me, are you uploading these files to your server? Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712537 Share on other sites More sharing options...
Pjack125 Posted December 11, 2008 Author Share Posted December 11, 2008 nope they will be on a network drive. just want to store the path info nothing else. I am making headway though... I am currently using <?php $_SESSION['IMG1'] = basename($_POST['ProgImg1']); ?> where $_POST['ProgImg1'] is info from the <input type=file name='ProgImg1'> field in a from. currently I am getting the output of Q:\\Engineering Web\\Test\\images\\Freescale_logo.jpg and i know there is a way to strip the slashes but i can't remember how... I really need to make a cheat sheet Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712568 Share on other sites More sharing options...
gevans Posted December 11, 2008 Share Posted December 11, 2008 strip slashes example; $foo = 'What\'s going on'; echo $foo.'<br />'; //output What\'s going on $bar = stripslashes($foo); echo $bar; //outputs What's going on Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712571 Share on other sites More sharing options...
gevans Posted December 11, 2008 Share Posted December 11, 2008 On that note, with your string; $foo = 'Q:\\Engineering Web\\Test\\images\\Freescale_logo.jpg'; echo stripslashes($foo); // Q:\Engineering Web\Test\images\Freescale_logo.jpg Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712576 Share on other sites More sharing options...
Pjack125 Posted December 11, 2008 Author Share Posted December 11, 2008 I Fingered it out . sorry folks i'm in a cube all by myself and you guys are the only ones I have for help . I hope i don't get too annoying. but I solved the problem by having this.... $_SESSION['IMG1'] = stripslashes(basename($_POST['ProgImg1'])); last question before i post this is there any way to not have to write this a million times because i have a bunch of fields that uses this and for efficiency reasons i also used. <?php foreach($_POST as $key => $val) //put every form value into a session variable in this page. { $_SESSION[$key] = $val; ?> some of theme will be just text fields and others are file fields how would is there a way to differentiate between them or will i just have to subject every field to stripslashes(basename($_POST['what ever field'])); Grr you guys are fast . [not complaining] Quote Link to comment https://forums.phpfreaks.com/topic/136490-solved-storing-complete-file-path-into-a-database/#findComment-712587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.