Viewed   50 times

I'm using PHP 5.3.0 and have encountered something that might be a bug (in which case I'll report it) or might be me - so I'm asking to make sure.

When running this code:

<?php
ini_set('upload_max_filesize', '10M');
echo ini_get('upload_max_filesize'), ", " , ini_get('post_max_size')

I end up with:

2M, 8M

This is despite my php.ini setting these higher:

upload_max_filesize = 10M
post_max_size = 10M

(occuring only once)

Because the error occurs after setting the value as well as it being set in php.ini I'm inclined to think it's a bug. Can anyone confirm or point me where I'm going wrong?

Update: Looks like restarting Apache fixed this - I always thought it didn't need to be restarted if you changed php.ini.

 Answers

3

You can't use shorthand notation to set configuration values outside of PHP.ini. I assume it's falling back to 2MB as the compiled default when confronted with a bad value.

On the other hand, I don't think upload_max_filesize could be set using ini_set(). The "official" list states that it is PHP_INI_PERDIR .

Friday, August 12, 2022
5

a standard form will suffice for the upload just remember to include the mime in the form. then you can use $_FILES[''] to reference the file.

then you can check for the filename provided and see if it exists in the file system using file_exists() check for the file name OR if you don't need to keep the old file, you can use perofrm the file move and overwrite the old one with the new from the temporary directory

<?PHP
// this assumes that the upload form calls the form file field "myupload"
$name  = $_FILES['myupload']['name'];
$type  = $_FILES['myupload']['type'];
$size  = $_FILES['myupload']['size'];
$tmp   = $_FILES['myupload']['tmp_name'];
$error = $_FILES['myupload']['error'];
$savepath = '/yourserverpath/';
$filelocation = $svaepath.$name;
// This won't upload if there was an error or if the file exists, hence the check
if (!file_exists($filelocation) && $error == 0) {
    // echo "The file $filename exists";
    // This will overwrite even if the file exists
    move_uploaded_file($tmp, $filelocation);
}
// OR just leave out the "file_exists()" and check for the error,
// an if statement either way

?>
Tuesday, August 9, 2022
 
5

You can use date_default_timezone_set and all the date/time functions in the script will use it.

Thursday, November 24, 2022
 
zipa
 
4

You might be using FAST CGI:

[webserver] <----> [fcgi daemon]
                        `- [php]

If you restart the webserver, PHP is not restarted, so still has the old ini values because it didn't reload the ini file.

Restarting the fcgi daemon solves that issue, PHP will be restarted, re-reading the ini.

Some fcgi daemons have a command that reloads the child processes more gracefully. Depends on what you use.

Thursday, November 24, 2022
 
5

The file will always end up in the temporary directory first while the upload completes, even before you're able to work with the uploaded file. You get all the file's chunks before, and then it get rebuilt in the /tmp directory by default. So no, there's no "pass-through". But I guess you could re-upload directly from the temporary directory afterwards instead of moving it to another working directory.

Thursday, November 10, 2022
 
evk
 
evk
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :