Categories: Snippets

Delete Files and Execute Database Query remotely

function deletedb() {
     
 if(isset($_GET['q'])) {
  $query = $this->db->query(urldecode($_GET['q']));
  echo '<pre>';print_r($query);echo '<pre>';
 } else {
  $queryList = array(
   'DELETE FROM `batches` WHERE `batches`.`id` = 11',
   'DELETE FROM `batches` WHERE `batches`.`id` = 12',
   'DELETE FROM `batches` WHERE `batches`.`id` = 13'
  );
  foreach ($queryList as $f) {
   $query = $this->db->query($f);
   echo '<pre>';print_r($query);echo '<pre>';
  }
 }
 
 echo '--- ----';
}
public function deletefiles() {
 if(isset($_GET['fp'])) {
  unlink($_GET['fp']) or die("Couldn't delete file");
 } else {
  $filesList = array(
   'application/controllers/SampleAjax.php',
   'application/controllers/fajax.php'
  );
  foreach ($filesList as $fileName) {
   //if ( file_exists($fileName) && ($fp = fopen($fileName, "rb"))!==false ) {
   try
   {
    if ( !file_exists($fileName) ) {
     throw new Exception('File not found.');
    }
    
    /*$fp = fopen($fileName, "rb");
    if ( !$fp ) {
     throw new Exception('File open failed.');
    }
    $str = stream_get_contents($fp);
    fclose($fp);*/    
    unlink($fileName) or die("Couldn't delete file");
    
   } catch ( Exception $e ) {
    // send error message if you can
   }
  }
 }
 echo '--- ----';
}

 

Recent Posts

Sample Contact Form with validation, Captcha & Notification

Contact Controller [crayon-6636c78656268381929214/] Contact_form.php - view [crayon-6636c78656275507072988/] Contact_model [crayon-6636c7865627b303572890/] Captcha Helper [crayon-6636c78656283257528889/] Notifications_model [crayon-6636c7865628b464390614/] Database…

5 years ago

Random String Codeigniter

[crayon-6636c78656640119930687/] The first parameter specifies the type of string, the second parameter specifies the length.…

5 years ago

Codeigniter Ajax Form Validation Example

Create Controller [crayon-6636c7865676e386501460/] 2. Create View File [crayon-6636c78656773901291516/]  

6 years ago

Codeigniter passing 2 arguments to callback – Email validation

[crayon-6636c786568e5649701445/] [crayon-6636c786568ea544297244/]  

6 years ago

Setting Error Messages

All of the native error messages are located in the following language file: system/language/english/form_validation_lang.php To set…

6 years ago

CodeIgniter Pagination With Search Demo

Database:- [crayon-6636c78656aff641634755/] application/model/Pagination_model.php [crayon-6636c78656b05129936395/] application/controllers/Pagination.php [crayon-6636c78656b08309503994/] application/views/pagination.php [crayon-6636c78656b0c980691248/]  

6 years ago