Hi,
I just noticed a strange behavior in file_save_upload where the resulting file permissions are different from one upload to the others with no reasons. Basically, here is the context where I can reproduce this behavior:
- I upload files using a form;
- I always upload the SAME file;
- I always upload from the same page;
- I more or less wait the same time before and after each upload.
When the form is submitted I do the following in mymodule_form_submit
mymodule_form_submit($form, &$form_state) {
// First test if filename is empty
if (empty($_FILES['files']['name']['file_field'])) {
drupal_set_message('Please, enter a correct file', 'error');
}
else {
if (user_access('upload file'))
{
$extensions = 'ext';
$validators = array(
'file_validate_extensions' => array(
$extensions
),
);
// DEBUG
drupal_set_message('PHP TMP File: ' . $_FILES['files']['tmp_name']['file_field']);
drupal_set_message($_FILES['files']['tmp_name']['file_field'] . ': ' . get_perms($_FILES['files']['tmp_name']['file_field']));
// END DEBUG
if ($file = file_save_upload('file_field', $validators)) {
drupal_set_message($file->filepath . ': ' . get_perms($file->filepath));
Most of the time, I get something like:
# PHP TMP File: /tmp/phpjaO4o8
# /tmp/phpjaO4o8: -rw-------
# sites/default/tmp/mytest.txt: -rw-r--r--
But once in a while, I get:
# PHP TMP File: /tmp/phpZAwiNw
# /tmp/phpZAwiNw: -rw-------
# sites/default/tmp/mytest.txt: -rw-rw-rw-
Why file permissions are not always the same after a file_save_upload?
Regards.
Comments