Tuesday, December 16, 2008

Generation of Photo Library

<html><head>

<script language="javascript">
function image_rep(x)
{
document.getElementById('imageshow').innerHTML="<img src='images/"+x+"'>";
}

</script>

</head><body>
<div style="clip: rect('top', 'right', 'bottom', 'left'); height:300px; width:300px; overflow:scroll; float:left; text-transform:lowercase;">
<?php
//Open images directory with chmod 0777
$dir = opendir("images");
$dir_image_no=0;
//List files in images directory
while (($file = readdir($dir)) !== false)
{

if ($file != "." && $file != "..")
{
echo "<a href='#' onClick='image_rep(\"".$file."\");'>". $file . "</a><br/>";

$dir_image_no++;
}

}
closedir($dir);
?>
</div>
<div align='left' id="imageshow" style="float:inherit"></div>
<div style="clear:both;"></div>

<div id="photo_lib_upload" >
<?
//code for image upload
if(isset($_POST['subFrm'])&&($_POST['subFrm']="1"))
{
$filename=$_FILES["photo"]["name"];
$ext=explode(".",$filename);
$arrlen=sizeof($ext); //length of array contaning file name

if((strtolower($ext[$arrlen-1])!="php")||(strtolower($ext[$arrlen-1])!="js"))
{
if((strtolower($ext[$arrlen-1])=="jpeg")||(strtolower($ext[$arrlen-1])=="jpg")||(strtolower($ext[$arrlen-1])=="png")||(strtolower($ext[$arrlen-1])=="gif"))
{

$finalname=time().str_replace(" ","_",$_FILES["photo"]["name"]); //echo"filename".$finalname;
move_uploaded_file($_FILES["photo"]["tmp_name"],"images/".$finalname);

$frm_inv="Your image has been uploaded successfully. <a href=# onclick='window.open(\"images/".$finalname."\",\"\",\"height=200,width=600,address=no\");return false;'> Click here </a>to View your uploaded image.";
$frm_col="black";

}
else
{
$frm_inv="Invalid file format :".$_FILES["photo"]["name"];
$frm_col="red";
}

}
else
{
$frm_inv="Invalid file format :".$_FILES["photo"]["name"];
$frm_col="red";
}


}

?>


<form action="" method="post" enctype="multipart/form-data" name="upload_frm">
<table>
<tr><td ALIGN="RIGHT">
<font face="Verdana" color="#75B04F"><strong>Image upload:</strong></FONT><br/><font face="Verdana" size="-2">(jpg, gif, png format only)</font>
</td>
<td class="td1" align="right"><input type="file" name="photo" onChange="img_uplo();"><input type="hidden" value="<?php echo $finalname; ?>" id="file"><input type="hidden" value="<?php echo $finalname; ?>" id="file1"><input type="hidden" name="subFrm" id="subFrm" value="1" />
</td>
</tr>
</table>
</form>
</body>

<script language="javascript">
function img_uplo()
{
document.upload_frm.submit();

}

</script>

</div>
<body>
</html>

Wednesday, November 26, 2008

PHP Code for sending email in HTML view

<?php

$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

// wordwrap mail message.
$message=wordwrap($message,70);


mail($to,$subject,$message,$headers);
?>

Show inside directory file and sub directory with PHP code

//Open images directory
$dir = opendir("images");

//List files in images directory
while (($file = readdir($dir)) !== false)
{
echo "filename: " . $file . "
";
}

//Resets the directory stream
rewinddir($dir);

//Code to check for changes

closedir($dir);
?>

Code for copy one file to another file with same directory in php

  1. php
  2. $text = file_get_contents('client.html');
  3. $paste = file_put_contents('client2.html',$text);
  4. if($paste)
  5. {
  6. echo "File copied correctly\n";
  7. } else {
  8. echo "There was a problem copying the file\n";
  9. }
  10. ?>

Wednesday, November 12, 2008

Question: What is the difference between the functions unlink and unset?

Question: What is the difference between the functions unlink and unset?
Answer:
unlink will delete a file and unset would remove a value from a session variable.

Question: What is meant by urlencode and urldecode?

Question: What is meant by urlencode and urldecode?

Answer:
string urlencode(str) where str contains a string for example “hello world” and the return value will be URL encoded and can be use to append with URLs‚ normaly used to appned data for GET like someurl.com?var=hello%world string urldocode(str) this will simply decode the GET variable’s value for example

echo (urldecode($_GET_VARS[var])) will output “Hello world”

Question: What is the functionality of the function strstr and stristr?

Question: What is the functionality of the function strstr and stristr?
Answer:
string strstr (string str1‚ string str2) this function search the string str1 for the first occurrence of the string str2 and returns the part of the string str1 from the first occurrence of the string str2. This function is case-sensitive and for case-insensitive search use stristr() function.


Example of strstr: $email = ’name@example.com’;
$domain = strstr($email‚ ’@’); echo $domain; // prints @example.com $user = strstr($email‚ ’@’‚ true); echo $user; // prints name ?>

Example of stristr: $email = ’USER@EXAMPLE.com’; echo stristr($email‚ ’e’); // outputs ER@EXAMPLE.com echo stristr($email‚ ’e’‚ true); // outputs US ?>

Kubernetes in one shotcat

root@srv509172:~# cat kind1/config.yaml   kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane   image: kindest/nod...