i got one simple logic to create a current year to 1900 select box. lets go for coding.
Date dNow = new Date( );
SimpleDateFormat = new SimpleDateFormat ("yyyy");
String year = ft.format(dNow);
int foo = Integer.parseInt(year);
while(foo > 1989)
ya , here is improved version of previous post. you can view all files within a particular directory as well as delete any file.
specially this kind of requirements came when i was working in Advertisement Management Module. so there admin can view all advertisement images which he uploaded previously and he can also able to delete from directory. so he can able to manage disk size.
k lets go for coding.
oky so first i need to fetch all images from directory with delete button. i m putting filename in button id value so i can easily recognize that for which file user pressing delete button. and once i’will get filename then rest of coding flow is very simple.. i will pass that filename to delete.jsp file and there i will write logic to delete that file.
and bellow screenshot is for listing of files from directory.
and now bellow jsp file show you delete function for that file
<%@ page import="java.io.*" %>
String id = request.getParameter("id");
File file = new File("C:\\Users\\LYMAN\\Documents\\NetBeansProjects\\WebApplication2\\web\\upload\\"+id+"");
out.println("file deleted successfully");
out.println("failed to perform delete operation");
hope you like this post.. 🙂
sometime it is necessary to check whether the uploaded file is valid Image file or not ? or sometime you need to allow user to upload only few image extension file. let’s say you want to allow user to upload only (gif, jpeg, jpg, png) extension file.
so let’s go for coding.
<form method="post" action="uploadimage.php" enctype="multipart/form-data">
<td> Upload Image here : </td>
<td> <input type="file" name="file"> </td>
<td> <input type="submit" value="upload"> </td>
PHP Coding (uploadimage.php)
$allowedExts = array("jpg", "jpeg", "gif", "png");
$arr = explode(".", $_FILES["file"]["name"]);
$extension = end($arr);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/jpg"))
&& in_array($extension, $allowedExts))
if ($_FILES["file"]["error"] > 0)
echo "Error: " . $_FILES["file"]["error"] . "<br />";
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"] );
echo "<script>alert('file uploaded successfully')</script>";
echo "Invalid file";
Please make sure that you have upload folder in your current directory.!
Hope you enjoy this small script!
sometime during your project you need to create some html elements dynamically based on user’s choice.
for example you are providing upload facilities to user such that initially only one upload widget is available but if user want to upload more things, they will click on add button and based on that upload widgets should created and appear there.
so you need to use two methods of jquery.
1) live method:
The live() method attaches one or more event handlers for selected elements, and specifies a function to run when the events occur.
Event handlers attached using the live() method will work for both current and FUTURE elements matching the selector (like a new element created by a script).
2) clone method:
The clone() method makes a copy of selected elements, including child nodes, text and attributes.
now let’s write code for creating dynamic elements.
<div class=’Option’><input type=’text’ name=’t1′/>
<span class=’Add’><img src=”add.png” height=”30″ width=”30″/></span>
if you press add button you will get another same row of textbox and add button.!
hope you like it.!