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. $foldername $_REQUEST['foldername'];
  18. $id $_REQUEST['id'];
  19. $file $_FILES['file'];
  20.  
  21. if(!CookieWorkshopid($id)) die('no way!');
  22.  
  23. if (!empty($_FILES)) {
  24.   $tempFile $_FILES['file']['tmp_name'];
  25.   $file $_FILES['file'];
  26.   $filename_parts pathinfo($_FILES['file']['name']);
  27.   $filename cleanString($filename_parts['filename']).'.'.$filename_parts['extension'];
  28.  
  29.   $targetPath dirname(__FILE__)DIRECTORY_SEPARATOR 'userfiles'DIRECTORY_SEPARATOR 'workgroups' DIRECTORY_SEPARATOR $foldername DIRECTORY_SEPARATOR;
  30.  
  31.   $targetFile str_replace('//','/',$targetPath$filename;
  32.  
  33.   if (in_array(strtolower($filename_parts['extension']),explode(','MEDIA_ALLOWED_EXT))) {
  34.     if(!file_exists(str_replace('//','/',$targetPath)))
  35.     mkdir(str_replace('//','/',$targetPath)0755true);
  36.  
  37.     move_uploaded_file($tempFile,$targetFile);
  38.     echo '{"name":"'.$filename.'","type":"'.$file['type'].'","size":"'.$file['size'].'"}';
  39.   else {
  40.     echo '{"error" : "File transfer error"}';
  41.   }
  42. }
  43. ?>

Documentation generated on Fri, 01 Apr 2011 09:35:17 +0200 by phpDocumentor 1.4.1