Shrinked jpgs download on some computers

chmiel

New Member
There is a web page, using a script to upload and download files.
The problem is: I upload some jpg files, and then in some cases, when I click "download", the files I get back are smaller than 'real' ones. For example, a 500k file becomes 40k after downloading (while it's still 500k on the server). It happens irregulary, on some computers, while on others it's all ok.
What can be the cause and how to workaround it?

The code is:
Code:
function downloadFile()
   {
      $config =& sobi2Config::getInstance();
      $database =& $config->getDb();
       $fid = sobi2Config::request($_REQUEST, "fid", 0);
       if($fid) {
         $query = "SELECT `filename`, `filetype`, `filesize`, `fileext`, `itemid` FROM `#__sobi2_plugin_download` WHERE `fid` = {$fid} AND `enabled` = 1";
         $database->setQuery($query);
         $file = null;
         if( !$config->forceLegacy && class_exists( "JDatabase" ) ) {
            $file = $database->loadObject();
         }
          else {
             $database->loadObject( $file );
          }
         if( $database->getErrorNum() ) {
            $config->logSobiError( "Download plugin. DB reports: ".$database->stderr() );
         }
         $query = "UPDATE `#__sobi2_plugin_download` SET `counter` = `counter` + 1 WHERE `fid` = {$fid}";
         $database->setQuery($query);
         $database->query();
       }
       else {
          trigger_error("sobi_download::downloadFile(): missing file id",E_USER_WARNING);
          return null;
       }
      if(!is_object($file)) {
         trigger_error("sobi_download::downloadFile(): DB error ($query)",E_USER_WARNING);
         return null;
      }

      $filePath = _SOBI_CMSROOT.DS.$this->directory.$file->itemid.DS.$file->filename;

      if(!file_exists($filePath)) {
         trigger_error("sobi_download::downloadFile(): file {$filePath} does not exist");
         return null;
      }

      $fileType = $this->mapExtension($file->fileext);
      ob_end_clean();
      ob_start();
      header("Content-Disposition: attachment; filename = \"{$file->filename}\"");
      header("Content-Type: {$fileType}");
      readfile($filePath);
      exit();
   }

Honestly, I don't think the code is wrong. Maybe some server or browser setting?

Thank you in advance for your help
Andrzej
 
Top