I'm having problem since long time in using file_save_upload($source,$dest) function.
If I dont use a destination $dest value, just use file_save_upload($source), file is saved in Windows temp folder, but if I do use it, the file is saved in my drupal "files" folder but the filename is wierd, for example, if I upload index.jpg, the file is renamed as "upload" and doesn't have any extension.

Here's the code:

                $source = file_check_upload('upload');
		$dir = variable_get('file_directory_path', 'files');
		if (file_save_upload($source,$dir)) { 
			drupal_set_message("Saved");
		}else{
			drupal_set_message("Not saved","error");
		}

and the Form looks like this:

$form['upload'] = array(
		 '#type' => 'file',
		 '#title' => t('Attach new file'),
		 '#size' => 40,
		 '#prefix' => '<tr><td>',
		 '#suffix' => '</td></tr>',
	);
$form['#attributes'] = array('enctype' => "multipart/form-data");

Comments

wqr786’s picture

Problem solved :)

I didn't create an uploads folder in the files directory where I was trying to upload the file. I created it, and it worked.

Here's the latest code:

$source = file_check_upload('upload');
$dir = variable_get('file_directory_path', 'files');
if (file_save_upload($source,$dir, FALSE)) { 
	drupal_set_message("Saved");
}else{
	drupal_set_message("Not saved","error");
}

Thanks
Waqar
4 Ace Technolog