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] => Array(
[tmppath] => temporary://p17g31n52jo4fvj31ds01efd189b4.tmp
[tmpname] => p17g31n52jo4fvj31ds01efd189b4.tmp
[name] => photo_1.jpg
[status] => 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' => 'plupload',
'#title' => 'Photos',
'#upload_validators' => array(
'file_validate_extensions' => array('jpg jpeg gif png'),
),
'#plupload_settings' => array(
'runtimes' => 'html5',
'chunk_size' => '1mb',
),
);
hook_form_validate() :
$file = file_save_upload('photos', array(
'file_validate_is_image' => array(),
'file_validate_extensions' => 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.
file_save_upload()
andfile_copy()
.