Copy the images to the public folder after form submit with PLupload in a custom module I have a custom module to create galleries using PLupload to upload multiple files. These files have a ".tmp" extension in my "/tmp" folder.

Here is an extract of my $form_state['values']:

[0] =&gt; Array(
    [tmppath] =&gt; temporary://p17g31n52jo4fvj31ds01efd189b4.tmp
    [tmpname] =&gt; p17g31n52jo4fvj31ds01efd189b4.tmp
    [name] =&gt; photo_1.jpg
    [status] =&gt; done
)


How do I save the files in my public folder with the good extension (like .jpg)?
I've tried using file_save_upload() or file_copy() but without success.

Can anyone help me?

I'm on a local server (wamp) as administrator with all permissions. The folders (tmp and site/default) are writable.

I copy here some extracts of my code.

hook_form() :

$form['create']['photos'] = array(
    '#type' =&gt; 'plupload',
    '#title' =&gt; 'Photos',
    '#upload_validators' =&gt; array(
        'file_validate_extensions' =&gt; array('jpg jpeg gif png'),
    ),
    '#plupload_settings' =&gt; array(
        'runtimes' =&gt; 'html5',
        'chunk_size' =&gt; '1mb',
    ),
);


hook_form_validate() :

$file = file_save_upload('photos', array(
    'file_validate_is_image' =&gt; array(),
    'file_validate_extensions' =&gt; array('png gif jpg jpeg'),
));

if ($file) {
    if ($file = file_move($file, 'public://')) {
        $form_state['storage']['file'] = $file;
    } else {
        form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
    }
} else {
    form_set_error('file', t('No file was uploaded.'));
}


It returns "No file was uploaded." I don't understand what I should put as first arguments to the file_save_upload function.
I finally manage to do what I want...

I didn't understand how to use file_copy ans its $destination argument. We can put a file path, not only a folder path. So, I can save my file.jpg correctly.

My code :

$values = $form_state['values']['create'];
$photos_count = count($values['photos']);
for ($i = 0; $i &lt; $photos_count; $i++) {
    $path = $values['photos'][$i]['tmppath'];
    $name = $values['photos'][$i]['name'];
    // set file datas as an object to pass it in file_copy()
    $file = (object)array(
        'uid' =&gt; 0,
        'uri' =&gt; $path,
        'filemime' =&gt; file_get_mimetype($path),
        'status' =&gt; 1
    );
    // copy the file in the correct folder
    if ($file = file_copy($file, $filepath . '/' . $name)) {
        drupal_set_message('Success');
    } else {
        drupal_set_message('Error', 'error');
    }
    // set the field datas for saving the node with an array
    $node-&gt;field_album_photos[$node-&gt;language][$i] = (array)$file;
}


Have a nice day !