Feeds:
Posts
Comments

If you need to validate the image dimension before uploading then the following script might be useful.
<?php
if(isset($_POST[‘button’])){
$filetmpname=$_FILES[“file”][“tmp_name”];
$dimension=getimagesize($filetmpname);
echo “width: “.$dimension[0].”<br />”;
echo “Height: “.$dimension[1];
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<body>
<form action=”” method=”post” enctype=”multipart/form-data” name=”form1″ id=”form1″>
<input type=”file” name=”file” id=”fileField” />
<input type=”submit” name=”button” id=”button” value=”Submit” />
</form>
</body>
</html>

<?php
if(isset($_POST[‘button’])){
$filename=$_FILES[‘file’][‘name’];
$break=explode(“.”,$filename);
$ext=$break[count($break)-1];
echo $ext;
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<body>
<form action=”” method=”post” enctype=”multipart/form-data” name=”form1″ id=”form1″>
<input type=”file” name=”file” id=”fileField” />
<input type=”submit” name=”button” id=”button” value=”Submit” />
</form>
</body>
</html>

If you need to put some data in a comma separated lists. This is suitable in forms with array of inputs.

<?php
$sql=mysql_query(“SOME QUERY”);
$delimeter=””;
$collection=””;
while($rs=mysql_fetch_array($sql)){
$collection.=$delimeter.$rs[‘SOME_FIELD’];
$delimeter=”,”;
}
echo $collection;
?>

Content Construction Kit (CCK) is one of the best module of Drupal. CCK module helps users to add custom fields to their nodes.  You can create a cck field to any content type easily, but i am going to show you how to add a custom field from a module. The code below shows how to add a text field to a content type from a module. Hope this help you and please post your valuable feedback.

<?php

$text_fields=array(‘field1′,’field2′,’field3’);
hook_install_cck_text_fields($text_fields, ‘CONTENT_TYPE_NAME’, $weight=20);

function hook_install_cck_text_fields($text_fields = array(), $type, $weight){
if (module_exists(‘text’)) {
foreach($text_fields as $text_fields => $text_field){
$field = content_fields(‘field_’ . $text_field);
  if (empty($field)) {
$field = array();
$field[‘field_name’] = ‘field_’ . $text_field;
$field[‘type_name’] = $type;
$field[‘type’] = ‘text’;
$field[‘module’] = ‘text’;
$field[‘required’] = FALSE;
$field[‘widget_type’] = ‘text_textfield’;
$field[‘active’] = TRUE;
content_field_instance_create($field);

$field = content_fields(‘field_’ . $text_field, $type);
$field[‘widget’][‘label’] = str_replace(“_”,” “,t(ucfirst($text_field)));
$field[‘widget’][‘weight’] = $weight++;
$field[‘widget’][‘type’] = ‘text_textfield’;
$field[‘display_settings’][‘weight’] = $weight;
$field[‘display_settings’][‘label’][‘format’] = ‘inline’;
$field[‘display_settings’][‘teaser’][‘format’] = ‘default’;
$field[‘display_settings’][‘full’][‘format’] = ‘default’;
content_field_instance_update($field);
}
else {
$field = content_fields(‘field_’ . $text_field, $type);
if (empty($field)) {
content_field_instance_create(array(‘field_name’ => ‘field_’ . $text_field, ‘type_name’ => $type));
}
}
}
}
}
?>