Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    basename function question

    Now correct me if I am wrong. But with PHP you should be able to do this:

    PHP Code:
    <?php

    $imagename 
    basename($_FILES['filename']['name']);

    ?>
    And just get the name of the image? So for am example the file was named 'example.jpg' it would show 'example'.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    No, basename just gets the name of the file unless you set the second parameter:

    PHP Code:
    echo basename('really/long/path/image.jpg');
    // Outputs image.jpg
    echo basename('really/long/path/image.jpg''.jpg');
    // Outputs image 

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Is there a function that will do this?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    pathinfo may work on an upload, you'll have to test it out:
    PHP Code:
    $sFileName pathinfo($_FILES['filename']['name'], PATHINFO_FILENAME); 
    Not certain if the pathinfo will work properly for you, but only one way to find out. Basename will work fine if you know what the extension is on it, but if you allow different image types, that won't work out.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •