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-69290dbf7d625226591705/] Contact_form.php - view [crayon-69290dbf7d62f170902489/] Contact_model [crayon-69290dbf7d634923315617/] Captcha Helper [crayon-69290dbf7d639851706325/] Notifications_model [crayon-69290dbf7d640393920806/] Database…

7 years ago

Random String Codeigniter

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

7 years ago

Codeigniter Ajax Form Validation Example

Create Controller [crayon-69290dbf7db1e306893819/] 2. Create View File [crayon-69290dbf7db26577883232/]  

7 years ago

Codeigniter passing 2 arguments to callback – Email validation

[crayon-69290dbf7dc4d094117579/] [crayon-69290dbf7dc52192174583/]  

7 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…

7 years ago

CodeIgniter Pagination With Search Demo

Database:- [crayon-69290dbf7df2a024193833/] application/model/Pagination_model.php [crayon-69290dbf7df2f797891792/] application/controllers/Pagination.php [crayon-69290dbf7df32560544756/] application/views/pagination.php [crayon-69290dbf7df37616835394/]  

7 years ago