Simple Image Validation Using JavaScript
Submitted by rinvizle on Wednesday, February 8, 2017 - 16:30.
In this tutorial we will create a Simple Image Validation Using JavaScript. This project is compose of Javascript and PHP. This project shows you how to validate an image file using a javascript function, every image file that the user uploaded it will save or copy automatically in the directory folder. Each image that the user upload a photo has a time stamp to determine the new file name.
Javascript Function for image validation format.
Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to LIKE & SHARE this website.
Sample Code
PHP Function for uploading an image file and copying to the directory folder.- <?php
- {
- $current_img=$_FILES['img_file']['name'];
- if (($extension!= "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png") && ($extension != "bmp"))
- {
- }
- $new_img = $time . "." . $extension;
- $destination="uploads/".$new_img;
- if (!$action)
- {
- }
- else
- {
- echo "<form align='center'>";
- echo "File Image Copy Successfully...";
- echo "<a href='index.php'> Back</a>";
- echo "</form>";
- }
- }
- else
- {
- ?>
- <body align="center">
- <form name="form" action="" enctype="multipart/form-data" method="post" onSubmit="return validate();">
- <h2>Upload Image</h2>
- <br />
- Upload An Image <input type="file" name="img_file"> <input type="submit" name="submit" value="Upload">
- </form>
- </body>
- <?php
- }
- ?>
- <script language="javascript">
- function validate()
- {
- var img_file = document.form.img_file.value;
- var img_length = document.form.img_file.value.length;
- var final_ext = ext.toLowerCase();
- for (i = 0; i < extensions.length; i++)
- {
- if(extensions[i] == final_ext)
- {
- return true;
- }
- }
- return false;
- }
- </script>
Add new comment
- 959 views