Monday, March 1, 2021

How to create folder inside the file and delete the file.


    $mydir_path = realpath( dirname( __FILE__ ).'/../../../../../libraries/TCPDF-master/pdf');
    $pdf_directory = file_prepare_directory($mydir_path, FILE_CREATE_DIRECTORY);

//get the folder path.
    
if($pdf_directory == false){
//Create the folder in drupal
      $create_dir_path = realpath( dirname( __FILE__ ).'/../../../../../libraries/TCPDF-master');
      drupal_mkdir($create_dir_path . "/pdf", $mode = NULL, $recursive = FALSE, $context = NULL);
  }


  $path = \Drupal::service('file_system')->realpath(file_default_scheme() . "://");
    //"C:\xampp7.4\htdocs\ProjectName\web\sites\default\files/demotest_1614594841.pdf"

  $file_path = $path . "/" . urlencode(trim(preg_replace('/\s+/','', $title)) . "_" . $request_time) .".pdf";

"C:\xampp7.4\htdocs\Projectname\web\sites\default\files/demotest_1614594841.pdf"

 $url = file_create_url($file->getFileUri());
//"http://tbknow.com/sites/default/files/demotest_1614594841.pdf"

 drupal_unlink($file_path , $context = NULL); //Deleted the file 

No comments:

Post a Comment

If you have any problem please let me know.