Anyone can help here please?

I have this use of file_save_upload function:

$file=file_save_upload('fichero', $validators, $directorio);

Well, this line works ok with Chrome, but using it with firefox 3.6.6 or IE, it don't uploads the file :-/

I have put the next sentence at the start of the submit function:

print_r($_FILES);

On Chrome, this is the result:
Array ( [files] => Array ( [name] => Array ( [fichero] => Jellyfish.jpg ) [type] => Array ( [fichero] => image/jpeg ) [tmp_name] => Array ( [fichero] => C:\xampp\tmp\phpC1F9.tmp ) [error] => Array ( [fichero] => 0 ) [size] => Array ( [fichero] => 775702 ) ) )

On Firefox and IE, with the SAME code:
Array ( )

Why please?

Thanks

Comments

to.stepan.kuzmin@gmail.com’s picture

Yeah, I`ve got same problem. My code is similiar I think so.

function advanced_video_widget(&$form, &$form_state, $field, $items, $delta = 0) {
    $output = array();
    $output['#attributes'] = array('enctype' => "multipart/form-data");
    $output['advanced_video_upload'] = array(
        '#type' => 'fieldset',
        '#title' => t('Upload video file'),
    );
    $output['advanced_video_upload']['advanced_video_upload_file'] = array(
        '#type' => 'file',
        '#title' => t('Attach video file'),
        '#size' => 40,
    );
    $output['advanced_video_upload']['advanced_video_upload_button'] = array(
        '#type' => 'submit',
        '#value' => t('Upload'),
        '#submit' => array('advanced_video_upload'), // Without javascript
    );
    return $output;
} // function advanced_video_widget
 
function advanced_video_upload($form, &$form_state) {
//    dvm($_FILES);
 
     $limits = array () ;
     $limits['extensions'] = array ('jpg') ;
 
     $validators = array(
         'file_validate_extensions' => array($limits['extensions']),
     );
 
     $file = file_save_upload('advanced_video_upload_file', $validators, file_directory_path());
     if ($file) {
         file_set_status($file, FILE_STATUS_PERMANENT);
     }
} // function advanced_video_upload
breos’s picture

Your code works with Chrome Kuzmin?

to.stepan.kuzmin@gmail.com’s picture

It does not work in any browser. It seems to me, that problem is in using CCK. My advanced_video_widget function describes an a CCK widget.
Everything works fine, using simple Form API function.

duckzland’s picture

Try changing this line and tell us if it is working or not

function advanced_video_widget(&$form, &$form_state, $field, $items, $delta = 0) {
    $form = array();
    $form['#attributes'] = array('enctype' => "multipart/form-data");
    $form['advanced_video_upload'] = array(
        '#type' => 'fieldset',
        '#title' => t('Upload video file'),
    );
    $form['advanced_video_upload_file'] = array(
        '#type' => 'file',
        '#title' => t('Attach video file'),
        '#size' => 40,
    );
    $form['advanced_video_upload']['advanced_video_upload_button'] = array(
        '#type' => 'submit',
        '#value' => t('Upload'),
        '#submit' => array('advanced_video_upload'), // Without javascript
    );
    return $form;
} // function advanced_video_widget

function advanced_video_upload($form, &$form_state) {
//    dvm($_FILES);

     $limits = array () ;
     $limits['extensions'] = array ('jpg') ;

     $validators = array(
         'file_validate_extensions' => array($limits['extensions']),
     );

     $file = file_save_upload('advanced_video_upload_file', $validators, file_directory_path());
     if ($file) {
         file_set_status($file, FILE_STATUS_PERMANENT);
     }
} // function advanced_video_upload

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

to.stepan.kuzmin@gmail.com’s picture

No, it does not working. Also it seems to me, that it is a wrong way, because I got 2 CCK widgets, after changing code.

to.stepan.kuzmin@gmail.com’s picture

Excuse me, this code is looks working.

function advanced_video_widget(&$form, &$form_state, $field, $items, $delta = 0) {
    $form['#attributes'] = array('enctype' => 'multipart/form-data');
    $form['advanced_video_upload'] = array(
        '#type' => 'fieldset',
        '#title' => 'Video file',
    );
    $form['advanced_video_upload']['advanced_video_file_upload'] = array(
        '#type' => 'file',
        '#title' => 'Filename'
    );
    $form['advanced_video_upload']['advanced_video_file_submit'] = array(
        '#type' => 'submit',
        '#value' => 'Upload file',
        '#submit' => array('advanced_video_upload'),
    );
    return $form;
}

function advanced_video_upload($form, &$form_state) {
    $validators = array();
    $file = file_save_upload('advanced_video_file_upload', $validators, file_directory_path());
    dvm($file);
} // function advanced_video_upload

Screenshot#1 Create content page.
Screenshot#2 Success upload.

duckzland’s picture

good to hear that


$form['advanced_video_upload']['advanced_video_file_upload'] = array(

this could be the difference but never know without further debugging :)

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

to.stepan.kuzmin@gmail.com’s picture

Thanks a lot for help! But what I should do with this problem? I mean that I got 2 CCK widgets (because function changes and return $form).

duckzland’s picture

try changing $form to $element, btw are you trying to build a custom cck element for uploading video? you do know that cck has video upload module that you can use right?

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

to.stepan.kuzmin@gmail.com’s picture

THANKS A LOT! I have found the solution.
I just need to add $element['#tree'] = FALSE to my CCK widget.

btw are you trying to build a custom cck element for uploading video? you do know that cck has video upload module that you can use right?

Yeah, I know about it, but I want to implement some more functionality.

Thanks again!