<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Validate Image</TITLE>
<META NAME="Author" CONTENT="Bit Repository">
<META NAME="Keywords" CONTENT="validate, extensions, file, javascript">
<META NAME="Description" CONTENT="A JavaScript Extension Validator for Images">
<SCRIPT LANGUAGE="JavaScript">
<!--
function validate()
{
var extensions = new Array("jpg","jpeg","gif","png","bmp");
var image_file = document.form.image_file.value;
var image_length = document.form.image_file.value.length;
var pos = image_file.lastIndexOf('.') + 1;
var ext = image_file.substring(pos, image_length);
var final_ext = ext.toLowerCase();
for (i = 0; i < extensions.length; i++)
{
if(extensions[i] == final_ext)
{
return true;
}
}
alert(" Upload an image file with one of the following extensions: "+ extensions.join(', ') +".");
return false;
}
//-->
</SCRIPT>
</HEAD>
<?php
if(isset($_POST['submit']))
{
$current_image=$_FILES['image_file']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png") && ($extension != "bmp"))
{
die('Unknown extension');
}
$time = date("fYhis");
$new_image = $time . "." . $extension;
$destination="uploads/".$new_image;
$action = copy($_FILES['image_file']['tmp_name'], $destination);
if (!$action)
{
die('File copy failed');
}
else
{
echo "File copy successful";
echo"<br>";
echo "<a href='upload_image.php'>Back</a>";
}
}
else
{
?>
<BODY>
<center>
<form name="form" action="" enctype="multipart/form-data" method="post" onSubmit="return validate();">
<h2>Upload an image</h2>
<br />
Upload an image: <INPUT type="file" name="image_file"> <input type="submit" name="submit" value="Submit">
</form>
</center>
</BODY>
<?php
}
?>
</HTML>
vijiglad 0 Newbie Poster
jkon 638 Posting Whiz in Training Featured Poster
vijiglad 0 Newbie Poster
jkon 638 Posting Whiz in Training Featured Poster
smantscheff commented: I'll take one million, too. You get half of it for your patience. +1
vijiglad 0 Newbie Poster
jkon 638 Posting Whiz in Training Featured Poster
vijiglad 0 Newbie Poster
jkon 638 Posting Whiz in Training Featured Poster
vijiglad 0 Newbie Poster
jkon 638 Posting Whiz in Training Featured Poster
vijiglad 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.