linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file upload.php

Documentation is available at upload.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage library
  5.  * @author Simon Georget <simon@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11. //header('Content-type: application/json');
  12. //header('Content-type: text/plain');
  13. include_once('../config/define.php');
  14. include_once('../lib/lib_common.php');
  15. include_once('../lib/functions_auth.php');
  16.  
  17. ////////////////////////////////////////
  18. /// Connexion SQL
  19. ///////////////////
  20. include_once('../class/system/class.'.SQL.'.php');
  21. $sql_entity=SQL;
  22. $GLOBALS['sql_object'new $sql_entity;
  23. $GLOBALS['sql_object'-> DBInitialise();
  24. $GLOBALS['sql_object'-> DBConnexion();
  25. ///////////////////
  26.  
  27. $foldername $_REQUEST['foldername'];
  28. $id $_REQUEST['id'];
  29. $file $_FILES['file'];
  30.  
  31. if(!isWorkgroupUser($id)) die('no way!');
  32.  
  33. if (!empty($_FILES)) {
  34.   $tempFile $_FILES['file']['tmp_name'];
  35.   $file $_FILES['file'];
  36.   $filename_parts pathinfo($_FILES['file']['name']);
  37.   $filename cleanString($filename_parts['filename']).'.'.$filename_parts['extension'];
  38.  
  39.   $targetPath dirname(__FILE__)DIRECTORY_SEPARATOR 'userfiles'DIRECTORY_SEPARATOR 'workgroups' DIRECTORY_SEPARATOR $foldername DIRECTORY_SEPARATOR;
  40.  
  41.   $targetFile str_replace('//','/',$targetPath$filename;
  42.  
  43.   if (in_array(strtolower($filename_parts['extension']),explode(','MEDIA_ALLOWED_EXT))) {
  44.     if(!file_exists(str_replace('//','/',$targetPath)))
  45.     mkdir(str_replace('//','/',$targetPath)0755true);
  46.  
  47.     move_uploaded_file($tempFile,$targetFile);
  48.     echo '{"name":"'.$filename.'","type":"'.$file['type'].'","size":"'.$file['size'].'"}';
  49.   else {
  50.     echo '{"error" : "File transfer error"}';
  51.   }
  52. }
  53. ?>

Documentation generated on Thu, 03 May 2012 15:08:00 +0200 by phpDocumentor 1.4.1