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-68b8c072386df604263416/] Contact_form.php - view [crayon-68b8c072386f1411211078/] Contact_model [crayon-68b8c072386fa687499235/] Captcha Helper [crayon-68b8c07238703216509913/] Notifications_model [crayon-68b8c07238710153074694/] Database…

7 years ago

Random String Codeigniter

[crayon-68b8c07238e67020084751/] 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-68b8c07238ffe744928485/] 2. Create View File [crayon-68b8c07239006535905612/]  

7 years ago

Codeigniter passing 2 arguments to callback – Email validation

[crayon-68b8c0723914b392586668/] [crayon-68b8c07239151679724167/]  

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-68b8c072399d0004923462/] application/model/Pagination_model.php [crayon-68b8c072399d8952710936/] application/controllers/Pagination.php [crayon-68b8c072399db116524905/] application/views/pagination.php [crayon-68b8c072399df653639392/]  

7 years ago