Subscribe For Free Updates!

We'll not spam mate! We promise.

Jun 17, 2013

Get all images from folder - php

Get all images from folder - php:

 The below code is used to get all images from folder in local system. we can set the condition for file type to read files from particular directory in php.

<?php
$imgdir = 'images/'; 
$allowed_types = array('png','jpg','jpeg','gif'); 
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
  if( in_array(strtolower(substr($imgfile,-3)),$allowed_types) OR
          in_array(strtolower(substr($imgfile,-4)),$allowed_types) )
/*If the file is an image add it to the array*/
  {$a_img[] = $imgfile;}
}
echo "<ul>";

 $totimg = count($a_img);

 for($x=0; $x < $totimg; $x++)
{
echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>";
}
echo "</ul>";


?>


 In the above coe $imgdir is used to pick your directory. $allowed_type is used to set the type of files u allowed from folder to pickup. 

opendir() function is used to open your given folder to read it.

readdir() is used to read folder. the while loop is read all files from folder and push the allowed type files in $a_img array.

Now we can print all image name by using for loop or any other method.


Jun 16, 2013

Javascript popup window to return value to parent window

Javascript popup window to return value to parent window:

 We can pass the values to child window to parent window by using javascript. These passing methodology working with html tags and javascript functions.

The javascript popup window is used to get the external value like select the region from map etc.

Follow the below html programs to pass the value from javascript popup window..

parent.html :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Opener</title>
<script type='text/javascript'>
function valideopenerform(){
var popy= window.open('popup.html','popup_form','location=no,menubar=no,status=no,top=50%,left=50%,height=550,width=750')
}
</script>
</head>

<body>
<form name='form1' id='form1' >
<input type='text' id='text1' name='text1' />
<input type='button' value='go' onclick='valideopenerform()' />
</form>

</body>

</html> 

 In this first html valideopenerform() is i used. in this function i called the second html for open as a popup window. and createone text field with the id "text1". i '' return the value to this text field from popup window.

popup.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Opener</title>
<script type='text/javascript'>
function validepopupform(){
window.opener.document.form1.text1.value=document.form2.text2.value;
self.close();
}
</script>

</head>

<body>
<form id='form2' name='form2' >
<input type='text' id='text2' name='text2' />
<input type='button' value='go' onclick='validepopupform()' />
</form>

</body>


</html> 

 In this second html i used validepopupform() to return the value to parent window text field by using text field id(text1).

Now the value passed to the parent window text field.