• 1.
    <?php
  • 2.
     
  • 3.
    //process.php
  • 4.
     
  • 5.
    if(!empty($_POST['foldddername'])) {
  • 6.
    		
  • 7.
    	require_once 'test.php';
  • 8.
    	$folder = new folder;
  • 9.
    	
  • 10.
    	$path = dirname( __FILE__ );
  • 11.
     
  • 12.
    	$foldername = strip_tags($_POST['foldddername']);
  • 13.
    	
  • 14.
    //	$folder ->crtFolder($foldername,$path);
  • 15.
    	if($message = $folder ->crtFolder($foldername,$path)) {
  • 16.
    		echo $message;
  • 17.
    	}
  • 18.
    }
  • 19.
     
  • 20.
     
  • 21.
    ?>
  • 22.
     
  • 23.
        <?php
  • 24.
     
  • 25.
    //test.php
  • 26.
     
  • 27.
    class folder
  • 28.
    {
  • 29.
    	
  • 30.
    	public function crtFolder($foldername,$path){
  • 31.
    		$dirpath = $path."\\".$foldername;
  • 32.
    	
  • 33.
    		if ((!is_dir($dirpath))) {
  • 34.
    			if(mkdir($dirpath,0777,true)) {
  • 35.
    				$error = false;
  • 36.
    				$message['error'] = false;
  • 37.
    				$message['message'] = "Folder Created";
  • 38.
    				return json_encode($message);
  • 39.
    			}
  • 40.
    				else { 
  • 41.
    					$error = true;
  • 42.
    					$message['error'] = true;
  • 43.
    					$message['message'] = "Folder Failed To Create";
  • 44.
    					return json_encode($message); 
  • 45.
    				}
  • 46.
    		}
  • 47.
    			else {
  • 48.
    				$error = true;
  • 49.
    				$message['error'] = true;
  • 50.
    				$message['message'] = "Folder Already Exists";
  • 51.
    				return json_encode($message);	
  • 52.
    			}
  • 53.
    	
  • 54.
    	}
  • 55.
    }
  • 56.
     
  • 57.
     
  • 58.
    ?> 
  • 59.
     
  • 60.
     
  • 61.
     
  • 62.
        //Ajax handling
  • 63.
     
  • 64.
    $(function(){
  • 65.
    $('.submittt').click(function(){
  • 66.
    		if($('input.folder-name').val() == "")
  • 67.
    		{
  • 68.
    			console.log('Please enter Folder Name');
  • 69.
    			return false;
  • 70.
    		}
  • 71.
    		else
  • 72.
    		{			
  • 73.
    			$.ajax
  • 74.
    			({
  • 75.
    				type: 'POST',
  • 76.
    				url: 'process.php',
  • 77.
    				dataType: 'json',
  • 78.
    				data:
  • 79.
    				{
  • 80.
    					foldddername: $('input.folder-name').val()
  • 81.
    				},
  • 82.
    				success:function(data)
  • 83.
    				{
  • 84.
    					console.log(data.message);
  • 85.
    					if(data.error === true)
  • 86.
    					{
  • 87.
    						console.log(data.message);
  • 88.
    					}
  • 89.
    					else
  • 90.
    					{
  • 91.
    						
  • 92.
    						console.log(data.message);
  • 93.
    						
  • 94.
    					}
  • 95.
    				},
  • 96.
    				error:function(XMLHttpRequest,textStatus,errorThrown)
  • 97.
    				{
  • 98.
    					console.log(data.message);
  • 99.
    				}
  • 100.
    			});
  • 101.
    			return false;
  • 102.
    		}
  • 103.
    	});	
  • 104.
    	
  • 105.
    });
<?php //process.php if(!empty($_POST['foldddername'])) { require_once 'test.php'; $folder = new folder; $path = dirname( __FILE__ ); $foldername = strip_tags($_POST['foldddername']); // $folder ->crtFolder($foldername,$path); if($message = $folder ->crtFolder($foldername,$path)) { echo $message; } } ?> <?php //test.php class folder { public function crtFolder($foldername,$path){ $dirpath = $path."\\".$foldername; if ((!is_dir($dirpath))) { if(mkdir($dirpath,0777,true)) { $error = false; $message['error'] = false; $message['message'] = "Folder Created"; return json_encode($message); } else { $error = true; $message['error'] = true; $message['message'] = "Folder Failed To Create"; return json_encode($message); } } else { $error = true; $message['error'] = true; $message['message'] = "Folder Already Exists"; return json_encode($message); } } } ?> //Ajax handling $(function(){ $('.submittt').click(function(){ if($('input.folder-name').val() == "") { console.log('Please enter Folder Name'); return false; } else { $.ajax ({ type: 'POST', url: 'process.php', dataType: 'json', data: { foldddername: $('input.folder-name').val() }, success:function(data) { console.log(data.message); if(data.error === true) { console.log(data.message); } else { console.log(data.message); } }, error:function(XMLHttpRequest,textStatus,errorThrown) { console.log(data.message); } }); return false; } }); });

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter