PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/file-upload.php

https://bitbucket.org/zym-works/hotel_system_api
PHP | 49 lines | 32 code | 6 blank | 11 comment | 9 complexity | 2483759b8aef3b047218cdadab3c1856 MD5 | raw file
  1. <?php
  2. /** Edit fields ending with "_path" by <input type="file"> and link to the uploaded files from select
  3. * @author Jakub Vrana, http://www.vrana.cz/
  4. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  5. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
  6. */
  7. class AdminerFileUpload {
  8. /** @var string @access protected */
  9. var $uploadPath, $displayPath;
  10. /**
  11. * @param string prefix for uploading data (create writable subdirectory for each table containing uploadable fields)
  12. * @param string prefix for displaying data, null stands for $uploadPath
  13. */
  14. function AdminerFileUpload($uploadPath = "../static/data/", $displayPath = null) {
  15. $this->uploadPath = $uploadPath;
  16. $this->displayPath = (isset($displayPath) ? $displayPath : $uploadPath);
  17. }
  18. function editInput($table, $field, $attrs, $value) {
  19. if (ereg('(.*)_path$', $field["field"])) {
  20. return "<input type='file' name='fields-$field[field]'>";
  21. }
  22. }
  23. function processInput($field, $value, $function = "") {
  24. if (ereg('(.*)_path$', $field["field"], $regs)) {
  25. $table = ($_GET["edit"] != "" ? $_GET["edit"] : $_GET["select"]);
  26. $name = "fields-$field[field]";
  27. if ($_FILES[$name]["error"] || !eregi('(\\.([a-z0-9]+))?$', $_FILES[$name]["name"], $regs2)) {
  28. return false;
  29. }
  30. //! unlink old
  31. $filename = uniqid() . $regs2[0];
  32. if (!move_uploaded_file($_FILES[$name]["tmp_name"], "$this->uploadPath$table/$regs[1]-$filename")) {
  33. return false;
  34. }
  35. return q($filename);
  36. }
  37. }
  38. function selectVal($val, &$link, $field) {
  39. if ($val != "&nbsp;" && ereg('(.*)_path$', $field["field"], $regs)) {
  40. $link = "$this->displayPath$_GET[select]/$regs[1]-$val";
  41. }
  42. }
  43. }