Ticket #11620 (closed defect (bug): fixed)
Upload Handling. Use is_numeric instead of ctype_digit.
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 2.9.1 |
| Component: | Upload | Version: | 2.9 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | eval@… |
Description
The function ctype_digit() is used in wp_handle_upload() in /wp-admin/includes/file.php
Please, replace with is_numeric().
Attachments
Change History
- Keywords has-patch added
- Type changed from defect (bug) to enhancement
- Milestone changed from Unassigned to 3.0
Could you give a reason why you want this change to be made?
- Cc eval@… added
Replying to scribu:
Could you give a reason why you want this change to be made?
is_numeric() is a standard function for php version 4 and 5, while ctype_digit() is avaliable only in the "ctype" extension, which may have no support at all. In WordPress they refused ctype starting from the version 2.5.1, see for reference http://core.trac.wordpress.org/search?q=ctype_digit
And now if the "ctype" extension is missing on the server, a WP user can't upload media in wordPress through the administration panel. Perhaps you should add this enhancement to 2.9.1 or 2.9.2 milestone.
For those user, that already have the same problem, I propose use the following snippet in the template functions.php
if(!finction_exists('ctype_digit')) {
function ctype_digit( $num ) { return is_numeric( $num ); }
}
Replying to markup:
Sorry. This one is correct.
if(!function_exists('ctype_digit')) {
function ctype_digit( $num ) { return is_numeric( $num ); }
}
A very good reason, but I don't think it will make it in 2.9.1.
Knowing the percentage of WP users that don't have the ctype extension would help in determining the severity of the issue.
- Type changed from enhancement to defect (bug)
- Milestone changed from 3.0 to 2.9.1
This should be 2.9.1, as this was introduced in 2.9 and therefore is a regression from 2.8.
Replying to markup:
if(!function_exists('ctype_digit'))
We would generally add those functions to compat.php. A plugin author could use it without knowing the ramifications, but at the same time, I don't think we currently account for any functions from extensions.
I grepped core and could not find another ctype_* function in use.
comment:7
automattor — 2 years ago
- Status changed from new to closed
- Resolution set to fixed
keep in mind that ctype_digit() does something else than is_numeric(). is_numeric is true for +0123.45e6 or 0xFF.
comment:10
azaozz — 2 years ago
In this case it only needs to check for numbers 0-8 returned as errors when uploading a file.

