how to get base path and dir name of file in php ?

Discussion in 'PHP' started by concreteseo, Aug 21, 2012.

  1. #1
    how to get base path and dir name of file in php ?
     
    concreteseo, Aug 21, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    That question is a little vague... what plussy pointed at is correct if you want to know about the php file that's currently running -- but if you have a filename or a relative path do you want the local path or the http path? (since they're two different things)... It's hard to say without more information since, well... vague.

    These may also be relevant to your question:
    http://us2.php.net/manual/en/function.parse-url.php
    http://us2.php.net/manual/en/function.pathinfo.php

    Sometimes you have to use all three in concert with each-other -- often times you'll have a local filesystem path, and need to turn it into a URL path -- which means taking $_SERVER['DOCUMENT_ROOT'] and stripping it off the start of the local path. Other times you'll have a URL path, and have to reverse it by stripping off the domain and protocol, and adding $_SERVER['DOCUMENT_ROOT'] at the start.

    Really, we need more information though.
     
    deathshadow, Aug 21, 2012 IP
  4. mastjaat

    mastjaat Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    use php tutorial or google book.
     
    mastjaat, Aug 22, 2012 IP
  5. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #5
    This is probably one of the most useless post I have ever seen.
     
    plussy, Aug 22, 2012 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #6
    This place seems overrun with these of late -- it's like we've got a upsurge of broken Engrish in five-word wonder-posters... reaching the point I want to get medieval on their tuchas' Samuel L. Jackson style... Englisc, mōdor wyrter! Gedōn ēow cweþan hit?
     
    deathshadow, Aug 22, 2012 IP
    plussy likes this.
  7. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #7
    hehe I like that
     
    plussy, Aug 22, 2012 IP
  8. mastjaat

    mastjaat Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #8
    use it

    <?php
    if(isset($_POST['b1']))
    {
    $path="img/";
    $fn=$_FILES['f1']['name'];
    $path=$path.$fn;
    if(move_uploaded_file($_FILES['f1']['tmp_name'],$path))
    {
    echo "The file ".$_FILES['f1']['name']. " has been uploaded";
    }
    else
    {
    echo "There was an error uploading the file, please try again!";
    }
    }
    ?>
    <form method="post" action="" enctype="multipart/form-data">
    select<input type="file" name="f1"><br>
    <input type="submit" name="b1" value="upload">
    </form>
     
    mastjaat, Aug 29, 2012 IP
  9. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #9
    Are you for real??
    anyone using that code will have their server compromised from day 1, do you really think its a good idea to allow anyone to upload any type of file without checking what type of file it is?
    You really shouldnt be giving advice like this untill you know what the hell you are talking about, go and learn about basic server security before posting crap like this.
     
    malky66, Aug 29, 2012 IP
  10. phpking

    phpking Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    yea very healpful
     
    phpking, Aug 30, 2012 IP
  11. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #11
    Yeah, Unlike the bunch of useless meaningless posts you have made on the forum just to boost your post count, i smell infractions heading your way..
     
    malky66, Aug 30, 2012 IP