Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- html form
- ------------------------------------------------------------------------------------------------------
- <form onsubmit="return false" class="form-horizontal" name="ads_post" id="post_form" enctype="multipart/form-data" method="post">
- <div class="form-group">
- <label class="control-label col-sm-2" >Image</label>
- <div class="col-sm-10">
- <table>
- <tr>
- <td><input type="file" class="file" name="file" id="input-upload-img1"></td>
- </tr>
- </table>
- </div>
- <span class="img_error"></span>
- </div>
- <div class="form-group">
- <div class="col-sm-offset-2 col-sm-10">
- <button type="submit" class="btn btn-primary" name="ad_submit">Submit</button>
- </div>
- </div>
- </form>
- --------------------------------------------------------------------------------------------------------
- validate.js
- --------------------------------------------------------------------------------------------------------
- $(document).ready(function(){
- function verify_img(img){
- $(".img_error").hide();
- if(img == ""){
- $(".img_error").show();
- $(".img_error").html("plz Choose an image");
- return false;
- }
- else{
- $(".img_error").show();
- $(".img_error").html("validating....");
- $.ajax({
- url:"classes/process.php",
- type: "POST",
- data: {check_img:1,img:img},
- success: function(data)
- {
- alert(data);
- },error: function(req, status, error) {
- // alert('Error: ' + req.status);
- console.log(error);
- console.log();
- }
- })
- }
- }
- $("#input-upload-img1").focusout(function(){
- var img=$("#input-upload-img1").val();
- verify_img(img);
- })
- })
- ---------------------------------------------------------------------------------------------------
- process.php
- ---------------------------------------------------------------------------------------------------
- <?php
- include "dbcon.php";
- class DataOperation extends database{
- public function verify_img($file){
- $regexp ="/\.(jpe?g|png)$/i";
- return (!preg_match($regexp,$title)) ? "Invalid_extension" : 'ok';
- }
- }
- $obj = new DataOperation;
- if(isset($_FILES['file']['check_img'])){
- $file=$_FILES['file']['img'];
- echo $data=$obj->verify_img($file);
- exit();
- }
- ?>
Add Comment
Please, Sign In to add comment