ckeditor.upload.inc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * elFinder Integration
  4. *
  5. * Copyright (c) 2010-2018, Alexey Sukhotin. All rights reserved.
  6. */
  7. /**
  8. * @file
  9. *
  10. * CKeditor Upload tab support
  11. */
  12. function elfinder_editor_upload_ckeditor() {
  13. $p = elfinder_get_user_profile();
  14. $dest = file_build_uri('');
  15. if (!strpos($p->settings['ckeditor_upload_directory'], '://')) {
  16. $dest .= $p->settings['ckeditor_upload_directory'];
  17. } else {
  18. $dest = $p->settings['ckeditor_upload_directory'];
  19. }
  20. $dest = elfinder_parse_path_tokens($dest);
  21. $destabs = drupal_realpath($dest);
  22. if (!file_prepare_directory($destabs, FILE_CREATE_DIRECTORY)) {
  23. drupal_set_message(t('Error. Cannot initialize directory %dir', array('%dir' => $destabs)), 'error');
  24. }
  25. $tmpf = $_FILES;
  26. foreach (array_keys($_FILES['upload']) as $key) {
  27. $tmpf['files'][$key]['upload'] = $_FILES['upload'][$key];
  28. }
  29. $_FILES = $tmpf;
  30. $file = file_save_upload('upload', array(), $dest);
  31. $file->status = FILE_STATUS_PERMANENT;
  32. file_save($file);
  33. header('Content-Type: text/html');
  34. print '<script type="text/javascript">';
  35. if ($file) {
  36. print "window.parent.CKEDITOR.tools.callFunction(2, '" . file_create_url($file->uri) . "', '');";
  37. } else {
  38. print "window.parent.CKEDITOR.tools.callFunction(2, '', '" . t('Error uploading file!') . "');";
  39. }
  40. print '</script>';
  41. exit();
  42. }