Hey,
I was attempting to use the upload file feature in importing data for a while, and I kept getting the error "File uploads are not allowed on this server.". I couldn't understand why because file uploads are allowed based on my settings.
Anyway, I dove into the source code and found this function:
function checkUpload()
{
$this->set('enable_upload', true);
if (strtolower(@ini_get('file_uploads')) == 'off'
|| @ini_get('file_uploads') == 0) {
$this->set('enable_upload', false);
}
}
The problem lies in @ini_get('file_uploads') == 0. I first removed that condition and it worked fine, but then I realized why that was yielding incorrect results. ini_get returns a string, so that 0 seems to need to be treated as a string: @ini_get('file_uploads') == '0' and that seemed to do the trick!
I hope this helps. Also, thanks so much for all of your amazing work. I've used phpmyadmin for years now and it truly is amazing.
Logged In: YES
user_id=210714
Originator: NO
I would like to reproduce this problem.
Which PHP version are you using?
Please run this test script and post the results:
<?php
if (ini_get('file_uploads') == 0) echo 'test 1 true ';
if (ini_get('file_uploads') == '0') echo 'test 2 true ';
if (ini_get('file_uploads') == 1) echo 'test 3 true ';
if (ini_get('file_uploads') == '1') echo 'test 4 true ';
?>
Logged In: YES
user_id=1383652
Originator: NO
FYI:
PHP_VERSION : 5.2.4 | PHP_OS : WINNT
var_dump( ini_get("file_uploads") ); : string(1) "1"
test 3 true 1
test 4 true "1"
____
PHP_VERSION : 5.2.0-8+etch7 | PHP_OS : Linux
var_dump( ini_get("file_uploads") ); : string(1) "1"
test 3 true 1
test 4 true "1"
cheers,
Jürgen
Logged In: YES
user_id=1383652
Originator: NO
hmm,
PHP_VERSION : 5.2.4 | PHP_OS : WINNT
I never would have expected this...
____
after setting "file_uploads Off" in php.ini:
var_dump( ini_get("file_uploads") ); : string(0) ""
test 1 true 0
____
*BUT* after setting "file_uploads 0" (zero) in php.ini:
var_dump( ini_get("file_uploads") ); : string(1) "0"
test 1 true 0
test 2 true "0"
____
all other settings like On, on, 1 or commenting that like lead to:
var_dump( ini_get("file_uploads") ); : string(1) "1"
test 3 true 1
test 4 true "1"
HTH
Logged In: YES
user_id=1383652
Originator: NO
why is this function needed at all and bloating the sessions?
the only place where its output $_SESSION...enable_upload=FALSE is used
is
line 891 in Config.class.php (trunk) only to set
$GLOBALS['is_upload'] = $this->get('enable_upload');
which easily could be replaced with
$GLOBALS['is_upload'] = ini_get('file_uploads') ? TRUE : FALSE;
Logged In: YES
user_id=943192
Originator: YES
Hey lem9,
When I run it, I get only test 1 true.
I'm running PHP Version 5.2.3 on a Linux server. And just another little bit of information, when I just echo ini_get('file_uploads'), it outputs "On".
What you might want to do is maybe do an is_numeric on it, and if it is numeric then check if it's 0 or 1, but if it's a string then check if it's on or off.
Hope this helps.
Regards,
~David
Logged In: YES
user_id=210714
Originator: NO
cooleo100d: I believe you but this is weird. On Linux with PHP 5.2.4, for me, echo ini_get('file_uploads') returns 1 and the value in php.ini is On.
The doc says "When querying boolean values: A boolean ini value of off will be returned as an empty string or "0" while a boolean ini value of on will be returned as "1". The function can also return the literal string of INI value."
So, I don't know in which situation the literal string is returned, but it is sometimes returned and we'll have to do additional checks like you suggested.
windkiel: I think that this is work in progress (or it should be progressing...); eventually we should get rid of $GLOBALS['is_upload'].
Logged In: YES
user_id=210714
Originator: NO
Please everyone test this (and don't forget to close your browser after a change in php.ini).
function checkUpload()
{
$this->set('enable_upload', true);
$tmp = (string) @ini_get('file_uploads');
if (empty($tmp) || '0' == $tmp || 'off' == strtolower($tmp)) {
$this->set('enable_upload', false);
}
}
Logged In: YES
user_id=1383652
Originator: NO
my suggestion
(avoiding $tmp and unnecessary steps when ini_get('file_uploads') is "0" or ""):
function checkUpload()
{
if(ini_get('file_uploads')) {
$this->set('enable_upload', true);
// if set "php_admin_value file_uploads Off" in httpd.conf
// ini_get() also returns the string "Off" in this case:
if('off' == strtolower(ini_get('file_uploads'))) {
$this->set('enable_upload', false);
}
} else {
$this->set('enable_upload', false);
}
}
PHP_VERSION : 5.2.4 (xampp) | PHP_OS : WINNT (w2k)
php.ini: file_uploads On
httpd.conf: php_admin_value file_uploads Off
var_dump( get_cfg_var("file_uploads") ); : string(1) "1"
var_dump( ini_get("file_uploads") ); : string(3) "Off"
ini_get... - $is_upload : >< 1 or nothing (how php displays booleans)
>cooleo100d: I believe you but this is weird.
maybe he has some such in his httpd.conf
Logged In: YES
user_id=943192
Originator: YES
Hey lem9,
The revised function you wrote seems to do the trick.
As for why ini_get returns the literal on or off for me, I'm not sure. But please note this is not a system I have set up in my house, it's a production server where the PHP installation was provided by Plesk, so that's the standard one they are sending down with their control panel.
And to windkiel: I don't like that function because right away you are treating ini_get('file_uploads') as a boolean, and it returns a string... I think you want to avoid a boolean statement like that and just do string comparison like lem did.
Logged In: YES
user_id=1383652
Originator: NO
>you are treating ini_get('file_uploads')as a boolean, ..
no, php takes care of that by implicitly converting strings to bool in an if clause ;)
If ini_get('file_uploads') returns "0" or "" nothing else but $this->set('enable_upload', false); needs to be done. Only otherwise we need to check whether it returns "off", "Off" or "OFF". Paranoid people would also test for "false".
YMMV
Logged In: YES
user_id=210714
Originator: NO
Merged windkiel's suggestion, thanks.
Logged In: YES
user_id=1383652
Originator: NO
p.s.
// if set "php_admin_value file_uploads Off" in httpd.conf
has to be
// if set "php_admin_flag file_uploads Off" in httpd.conf
to really take effect!