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-67a5ae7e785cd288479624/] Contact_form.php - view [crayon-67a5ae7e785d8136797487/] Contact_model [crayon-67a5ae7e785dd642201618/] Captcha Helper [crayon-67a5ae7e785e4167568573/] Notifications_model [crayon-67a5ae7e785eb122345862/] Database…

6 years ago

Random String Codeigniter

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

6 years ago

Codeigniter Ajax Form Validation Example

Create Controller [crayon-67a5ae7e789cd903407680/] 2. Create View File [crayon-67a5ae7e789d0567498580/]  

7 years ago

Codeigniter passing 2 arguments to callback – Email validation

[crayon-67a5ae7e78b0c158341601/] [crayon-67a5ae7e78b10731795735/]  

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-67a5ae7e78cc4583415425/] application/model/Pagination_model.php [crayon-67a5ae7e78cc8138823803/] application/controllers/Pagination.php [crayon-67a5ae7e78ccb867677412/] application/views/pagination.php [crayon-67a5ae7e78cce658072515/]  

7 years ago