Changeset 38722 in spip-zone for _plugins_/ddUpload


Ignore:
Timestamp:
Jun 9, 2010, 10:18:58 PM (9 years ago)
Author:
renato@…
Message:

effacher les fichiers temp de upload a la fin de l'action;
mise a jour du code upload pour les icones

Location:
_plugins_/ddUpload/action
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • _plugins_/ddUpload/action/iconifier.php

    r38580 r38722  
    5656    if (isset($_SERVER['HTTP_X_FILE_NAME']) && isset($_SERVER['CONTENT_LENGTH'])) { 
    5757      if($_SERVER['CONTENT_LENGTH']>0) {
    58         $uploadedContent = file_get_contents("php://input");
    59         //detect data URI
    60         if (preg_match("/^data:[^;]+(;charset=\"[^\"]+\")?(;base64)?,/",$uploadedContent,$m)) {
    61           if($m[2]) //base64 encoded -> decode data
    62             $uploadedContent = base64_decode(substr($uploadedContent,strlen($m[0])));
    63           else //no decode, just strip headers
    64             $uploadedContent = substr($uploadedContent,strlen($m[0]));
     58        $handle = fopen("php://input","rb");
     59        $block = fread($handle,4096);
     60        $blocklen = strlen($block);
     61        $base64 = false;
     62        $dest = tempnam(_DIR_TMP, 'tmp_upload');
     63        $handle_dest = fopen($dest,"ab");
     64        if (preg_match("/^data:[^;]+(;charset=\"[^\"]+\")?(;base64)?,/",$block,$m)) {
     65          //data uri
     66          $base64 = $m[2];
     67          $block = substr($block,strlen($m[0]));
     68          if($base64) {
     69            $blocklen -= $m[0];
     70            $blockleft = $blocklen % 4;
     71            if($blockleft) {
     72              $block .= fread($handle,$blockleft);
     73            }
     74            $block = base64_decode($block);
     75          } 
    6576        }
    66         file_put_contents($tmp_dir = tempnam(_DIR_TMP, 'tmp_upload'),$uploadedContent);
    67         $source = array("name" => $_SERVER['HTTP_X_FILE_NAME'], "tmp_name" => $tmp_dir, "error" => 0);
     77        fwrite($handle_dest,$block);
     78        while($block = fread($handle,4096)) {
     79          if($base64)
     80            $block = base64_decode($block);
     81          fwrite($handle_dest,$block);
     82        }
     83        fclose($handle);
     84        fclose($handle_dest);
     85        $source = array("name" => $_SERVER['HTTP_X_FILE_NAME'], "tmp_name" => $dest, "error" => 0);
    6886      } else {
    6987        spip_log("file upload error");
     
    136154       
    137155        }
     156
     157  if($dest)
     158    @unlink(@dest);     
    138159}
    139160?>
  • _plugins_/ddUpload/action/joindre.php

    r38619 r38722  
    103103        $type_image = $sousaction($path, $mode, $type, $id, $id_document,
    104104                 $hash, $redirect, $documents_actifs, $iframe_redirect);
    105 
     105 
     106  if($dest)
     107    @unlink($dest);
     108 
    106109        $redirect = urldecode($redirect);
    107110        if ($documents_actifs) {
Note: See TracChangeset for help on using the changeset viewer.