fckeditor.upload.inc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * elFinder Integration
  4. *
  5. * Copyright (c) 2010-2018, Alexey Sukhotin. All rights reserved.
  6. */
  7. /**
  8. * @file
  9. *
  10. * FCKeditor Upload tab support
  11. */
  12. function elfinder_editor_upload_fckeditor() {
  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['NewFile']) as $key) {
  27. $tmpf['files'][$key]['NewFile'] = $_FILES['NewFile'][$key];
  28. }
  29. $_FILES = $tmpf;
  30. $file = file_save_upload('NewFile', 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.OnUploadCompleted(0, '" . file_create_url($file->uri) . "', '" . $file->filename . "', '') ;";
  37. } else {
  38. print 'window.parent.OnUploadCompleted(1,"","", "' . t('Error uploading file!') . '") ;';
  39. }
  40. print '</script>';
  41. exit();
  42. }