Jump to content

[SOLVED] Storing complete file path into a database.


Recommended Posts

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

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.

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...

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  :(

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

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]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.