I'm just the newbie in module developing. I have some problem in file uploading. Can you show me how i can upload a file, please?
Thanx a lot.

Comments

WorldFallz’s picture

The process is essentially the same as in version 5, though the settings are located at slightly different paths.

drupal.org --> Documentation --> Getting Started --> Core Modules --> Upload: collaborate with files

Content Type settings are at admin/content/types and permissions are at admin/user/permissions.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

kyphong’s picture

function uploadfile_admin(){
	$form = array();
	$form['#attribute']['enctype'] = 'multipart/form-data';
	$form['file'] = array(
		'#title' => t('Upload a File'),
		'#description' => t('Browse a file to upload.'),
		'#type' => 'file',
	);
	$form['submit'] = array(
		'#type' => 'submit',
		'#value' => t('Upload'), 
	);
	return $form;
}

function uploadfile_menu(){
	$item = array();
	$item['admin/settings/uploadfile'] = array(
		'title' => t('Upload a file to server.'),
		'description' => t('You can browse and upload file to the server'),
		'page callback' => 'drupal_get_form',
		'page arguments' => array(uploadfile_admin),
		'access arguments' => array('admin site configuration'),
		'type' => MENU_NORMAL_ITEM,
	);
	return $item;
}
function uploadfile_admin_submit($form, &$form_state){
	$file = file_check_upload('file'); // It's not available in Drupal 6.0
	$file = file_save_upload($file,file_directory_path());
	if($file){
		t('Successful.');
	}else{
		t('Failed','error');
	}
}

I have done like this article show, but file_check_upload('file') does not support in drupal 6.0, can you help me?
http://groups.drupal.org/node/10305

thomasmeadows’s picture

I had the same issue...I was able to get the upload to work like this...

  $dstnme = variable_get('file_directory_path', NULL);  //path to files directory
  if (($file = file_save_upload('file')) != FALSE) {  // is the file an actual file?
    file_copy($file, $dstnme, FILE_EXISTS_REPLACE);  // if yes, copy the file /  if it exist replace it
    drupal_set_message(t('Your picture has been uploaded'));
  }else{
    drupal_set_message(t('There was an error uploading your picture'));
kyphong’s picture

I have just copy your code to my module, but actually, it doesn't work. It display the message "There was an error uploading your picture".

shunting’s picture

$form['#attributes']['enctype'] = 'multipart/form-data';

http://www.universalpantograph.com