php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32349 basename with \
Submitted: 2005-03-17 09:28 UTC Modified: 2005-03-31 01:00 UTC
From: zamorov at edinorog dot ru Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: php4-STABLE-200503181130 OS: FreeBSD
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-03-17 09:28 UTC] zamorov at edinorog dot ru
Description:
------------
basename not work correctly with windows path

Reproduce code:
---------------
$win = basename('C:\Windows\win.ini');
$unix = basename('/usr/local/etc/win.ini');

Expected result:
----------------
$win = 'win.ini';
$unix = 'win.ini';

Actual result:
--------------
$win = 'C:\Windows\win.ini';
$unix = 'win.ini';

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-18 14:41 UTC] zamorov at edinorog dot ru
That problem remained open.
 [2005-03-18 15:08 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Qutiong php.net/basename 
 
"On Windows, both slash (/) and backslash (\) are used as 
directory separator character. In other environments, it is 
the forward slash (/)." 
 [2005-03-20 11:28 UTC] zamorov at edinorog dot ru
Sample. I'm upload file from windows to unix.

$_FILES[etc]['name'] contain path with backslash, but basename understand only forward slash.

Use
$imageName =& array_pop(split('/', strtr($_FILES['image']['name'], array('\\' => '/'))));
rather than
$imageName =& basename($_FILES['image']['name']);
wise choice?
 [2005-03-20 11:42 UTC] tony2001@php.net
On unix "\name\containing\slashes" is a perfectly valid *directory or file* name, so why do we have to force users not to use such names? 

 [2005-03-31 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 23 03:01:29 2019 UTC