Uncategorized

Upload CSV File in PHP

 <?php // Load the database configuration fileinclude_once ‘dbConfig.php’; // Get status messageif(!empty($_GET[‘status’])){ switch($_GET[‘status’]){ case ‘succ’: $statusType = ‘alert-success’; $statusMsg = ‘Members data has been imported successfully.’; break; case ‘err’: $statusType = ‘alert-danger’; $statusMsg = ‘Some problem occurred, please try again.’; break; case ‘invalid_file’: $statusType = ‘alert-danger’; $statusMsg = ‘Please upload a valid CSV file.’; break; …

Upload CSV File in PHP Read More »

validate csv file header

 <?php $files = glob(“$PathToCreate$version/*.csv”); foreach($files as $file) { if (($handle = fopen($file, “r”)) !== FALSE) { echo “<b>Filename: ” . basename($file) . “</b><br><br>”; while (($data = fgetcsv($handle, 4096, “,”)) !== FALSE) { echo implode(“t”, $data); } echo “<br>”; fclose($handle); } else { echo “Could not open file: ” . $file; } }?>

loop

  for (let i = 0; i < 3; i++) { var data = ‘<div class=”row”>’; for (let j = 1; j < 5; j++) { data += ‘<div class=”col-sm-‘ + j + ‘”>’; data += `<div class=”card” style=”width: 18rem;”> <img src=”…” class=”card-img-top” alt=”…”> <div class=”card-body”> <h5 class=”card-title”>Card title</h5> <p class=”card-text”>Some quick example text to …

loop Read More »

wordpress wp list table pagination

  first page page_no = 1 previous page <?php if ($page_no >=2) {echo $page_no–1;}else{echo ‘1’;}?> //current page <?php echo $page_no; ?> // the next page <?php if ($page_no >=1 && $page_no <$total_pages) { echo $page_no+1; } else { echo $page_no; } ?> //last page <?php echo $total_pages; ?>

add post meta box and save it to db

 //adding meta box to each post type for auto notifications add_action(‘admin_init’,‘add_custom_fields’); function add_custom_fields( ) { $screens = get_post_types(); foreach ( $screens as $screen ) { add_meta_box( ‘pnr-auto-push-notifications’, ‘Push Notification Reloaded’, ‘pnr_auto_push_notifications’, $screen, ‘side’, ‘high’, ); } } function pnr_auto_push_notifications($post){ $notification_status = get_post_meta( $post->ID, ‘pnr-auto-push-notifications’,true); ?> <input type=“checkbox” name=“auto_push_notifications” id=“auto_push_notifications” <?php if($notification_status == ‘on’) echo ‘checked’?> …

add post meta box and save it to db Read More »

wordpress add option checkbox and retrive data

 <form method=“post” action=“”> <span>Select languages</span><br/> <input type=“checkbox” name=‘lang[]’ value=“PHP”> PHP <br/> <input type=“checkbox” name=‘lang[]’ value=“JavaScript”> JavaScript <br/> <input type=“checkbox” name=‘lang[]’ value=“jQuery”> jQuery <br/> <input type=“checkbox” name=‘lang[]’ value=“Angular JS”> Angular JS <br/> <input type=“submit” value=“Submit” name=“submit”> </form> <?php if(isset($_POST[‘submit’])){ if(!empty($_POST[‘lang’])) { foreach($_POST[‘lang’] as $value){ echo “value : “.$value.‘<br/>’; } } update_option( ‘pnr_post_type’,$_POST[‘lang’] ); } ?> get …

wordpress add option checkbox and retrive data Read More »

wordpress auto send email to admin on page /post update or publish

 //post and page updated -send email to admin function pnr_auto_send_email( $post_id ) { global $post; // If this is just a revision, don’t send the email. if( $post->post_type == ‘post’){ $post_title = get_the_title( $post_id ); $post_url = get_permalink( $post_id ); if ( $post->post_date != $post->post_modified) { //update $subject = ‘A post has been updated’; } …

wordpress auto send email to admin on page /post update or publish Read More »

GET Location from ip in php

   $ip = ‘117.197.234.146’; $details = json_decode(file_get_contents(“http://ipinfo.io/{$ip}/json”)); echo $details->city; // -> “Mountain View” return stdClass Object( [ip] => 117.197.234.146 [city] => Bhubaneshwar [region] => Odisha [country] => IN [loc] => 20.2724,85.8338 [org] => AS9829 National Internet Backbone [postal] => 752115 [timezone] => Asia/Kolkata [readme] => https://ipinfo.io/missingauth)