OldWest Posted December 7, 2010 Share Posted December 7, 2010 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 https://forums.phpfreaks.com/topic/220900-why-does-basename-work-as-follows/ Share on other sites More sharing options...
OldWest Posted December 7, 2010 Author Share Posted December 7, 2010 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 https://forums.phpfreaks.com/topic/220900-why-does-basename-work-as-follows/#findComment-1143888 Share on other sites More sharing options...
OldWest Posted December 7, 2010 Author Share Posted December 7, 2010 oh shit.. its too late. i misread the manual on this function! working as expected. Link to comment https://forums.phpfreaks.com/topic/220900-why-does-basename-work-as-follows/#findComment-1143889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.