PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/xmp/fm/fm/uploadfile.php

https://github.com/se3/xmp
PHP | 73 lines | 51 code | 11 blank | 11 comment | 14 complexity | 9beb45537a182024bb2167e97eeeb79a MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * Copyright (C) 2006 - 2007, West-Web Limited.
  4. *
  5. * Nickolay Shestakov <ns@ampex.ru>
  6. *
  7. * This program is free software, distributed under the terms of
  8. * the GNU General Public License Version 2. See the LICENSE file
  9. * at the top of the source tree.
  10. */
  11. session_start();
  12. if(!$_SESSION['fm_entry']) die('Not a Valid Entry');
  13. include_once("../lang/".$_SESSION['lang'].".lang.php");
  14. include_once("../config.php");
  15. include_once("../lib/func.php");
  16. include_once("../lib/sysfunc.php");
  17. $dir=stripslashes_r($_POST['upload_dir']);
  18. $type=$_POST['type'];
  19. $new_name = stripslashes_r($_POST['new_name']);
  20. if($type == 'remote') {
  21. $prog = $_POST['prog'];
  22. $remote_file = stripslashes_r($_POST['remote_file']);
  23. $progtype = $_POST['progtype'];
  24. if($new_name) $local_file=$dir."/".$new_name;
  25. else $local_file=$dir."/".substr(strrchr($remote_file,'/'),1);
  26. //echo "type=$progtype dir=$dir type=$type remote_file=$remote_file local=$local_file"; exit();
  27. if($progtype=="copy") {
  28. @copy($remote_file,$local_file);
  29. }else {
  30. $remote_file=escapeshellarg($remote_file);
  31. $local_file=escapeshellarg($local_file);
  32. switch ($progtype) {
  33. case 'wget': $cmd=$prog." ".$remote_file." -O ".$local_file; break;
  34. case 'curl': $cmd=$prog." ".$remote_file." -o ".$local_file; break;
  35. case 'links': $cmd=$prog." -source ".$remote_file." > ".$local_file; break;
  36. case 'lynx': $cmd=$prog." -source ".$remote_file." > ".$local_file; break;
  37. }
  38. //echo hc($cmd); exit();
  39. execute($cmd);
  40. }
  41. if(!file_exists($local_file))
  42. echo "fm.showMessage('$strErrorUploadFile','filemanager-message',0,'warning.gif');";
  43. else echo "fm.hlfiles.push('".addslashes($local_file)."'); fm.showDir('".addslashes($dir)."'); ";
  44. exit();
  45. }
  46. echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body>";
  47. $file=$_FILES['upload_local_file']['tmp_name'];
  48. if(!file_exists($file)) {
  49. echo "<script type='text/javascript'>parent.fm.showMessage('$strErrorUploadFile','filemanager-message',1,'warning.gif');</script></body></html>";
  50. exit();
  51. }
  52. $file_name=$_FILES['upload_local_file']['name'];
  53. $file_size=$_FILES['upload_local_file']['size'];
  54. $error=$_FILES['upload_file']['error'];
  55. if($new_name) $full_file_name=$dir."/".$new_name;
  56. else $full_file_name=$dir."/".$file_name;
  57. $res = move_uploaded_file($file,$full_file_name);
  58. echo "<script type='text/javascript'>";
  59. echo "parent.fm.hideSrv(); ";
  60. if(!$res) echo "parent.fm.showMessage('$strErrorUploadFile : ".addslashes($full_file_name)."','filemanager-message',1,'warning.gif');";
  61. else echo " parent.fm.hlfiles.push('".addslashes($full_file_name)."'); parent.fm.showDir('".addslashes($dir)."');";
  62. echo "</script></body></html>";