Jump to content

Why does basename() work as follows?


OldWest

Recommended Posts

I am doing some study, and I am looking through an upload script.. Can someone explain to me why this is so:

 

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']

);

 

From reading the manual and looking at other tutorials, it appears basename() returns the file path name thus would strip off the actual file name in the above??

 

For example if $_FILES['userfile']['name'] was mike.jpg wouldn't basename() just snag "mike"?

 

Am I right??

 

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

 

 

Link to comment
Share on other sites

I still don't know why basename() is used. I ran this test:

 

<form  method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="submit" type="submit" value="Go >>" />
</form>

<?php
if(isset($_POST['submit'])) {
  $uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename("ed.png");
echo $uploadfile;
}
?>

 

Output is: /var/www/uploads/ed.png

 

But why is basename() needed or recommended in so many examples?

 

Link to comment
Share on other sites

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.