Changeset 25 for types/File


Ignore:
Timestamp:
Nov 20, 2008, 12:19:52 PM (16 years ago)
Author:
george
Message:
  • Upraveno: Data přijatých souborů neukládat přímo do databáze, ale ponechat je na disku.
Location:
types/File
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • types/File/File.php

    r22 r25  
    77    global $Database;
    88
    9     $DbResult = $Database->query('SELECT `Name`, LENGTH(`Content`) FROM `SystemFile` WHERE `Id`='.$Item['Value']);
     9    $DbResult = $Database->query('SELECT `Name`, `Size` FROM `SystemFile` WHERE `Id`='.$Item['Value']);
    1010    if($DbResult->num_rows > 0)
    1111    {
    1212      $DbRow = $DbResult->fetch_assoc();
    13       return('<a href="types/File/FileDownload.php?Id='.$Item['Value'].'">'.$DbRow['Name'].'</a> ('.HumanSize($DbRow['LENGTH(`Content`)']).')');
     13      return('<a href="types/File/FileDownload.php?Id='.$Item['Value'].'">'.$DbRow['Name'].'</a> ('.HumanSize($DbRow['Size']).')');
    1414    } else return('');
    1515  }
     
    2626  function OnLoad($Item)
    2727  {
    28     global $Database;
     28    global $Database, $Config;
    2929
    3030    $Result = 0;
     
    3434      if(file_exists($_FILES[$Item['Name']]['tmp_name']))
    3535      {
    36         $Content = file_get_contents($_FILES[$Item['Name']]['tmp_name']);
    3736        $FileName = substr($_FILES[$Item['Name']]['name'], strrpos($_FILES[$Item['Name']]['name'], '/'));
    38         $Database->query('INSERT INTO SystemFile (`Name`, `Content`) VALUES ("'.$FileName.'", 0x'.bin2hex($Content).')');
     37        $Database->query('INSERT INTO SystemFile (`Name`, `Size`) VALUES ("'.$FileName.'", '.filesize($_FILES[$Item['Name']]['tmp_name']).')');
    3938        $Result = $Database->insert_id;
    40         unlink($_FILES[$Item['Name']]['tmp_name']);
     39        if(!move_uploaded_file($_FILES[$Item['Name']]['tmp_name'], $Config['UploadFileFolder'].'/'.$Result)) SystemMessage('Nahrání souboru', 'Cílová složka není dostupná!');
    4140      }
    4241    }
  • types/File/FileDownload.php

    r21 r25  
    1818  Header('Content-Type: '.DetectMimeType($DbRow['Name']));
    1919  Header('Content-Disposition: attachment; filename="'.$DbRow['Name'].'"');
    20   echo($DbRow['Content']);
     20  echo(file_get_contents($Config['UploadFileFolder'].'/'.$DbRow['Id']));
    2121} else echo('Soubor nenalezen!');
    2222
Note: See TracChangeset for help on using the changeset viewer.