Exemple #1
0
 /**
  * gets a file pointer from a specified file
  * @param   string $filename
  * @param array $options
  * @return  mixed $res file pointer | true | false
  */
 public static function getFPFromFile($filename, $options = array())
 {
     if (isset($options)) {
         self::$options = $options;
     }
     if (!file_exists($filename)) {
         self::$errors[] = lang::translate('File does not exists') . ' : ' . $options['filename'];
         return false;
     }
     if (isset($options['maxsize'])) {
         $size = filesize($options['filename']);
         //  check the file is less than the maximum file size
         if ($size > $options['maxsize']) {
             $error = lang::translate('File is too large.');
             $error .= lang::translate('Max size is ') . upload::bytesToGreek($options['maxsize']);
             error_log($error);
             self::$errors[] = $error;
             return false;
         }
     }
     // check for right content
     if (isset($options['allow_mime'])) {
         $type = file::getMime($options['filename']);
         if (!in_array($type, $options['allow_mime'])) {
             self::$errors[] = lang::translate('This Content type is not allowed') . MENU_SUB_SEPARATOR_SEC . $type;
             return false;
         }
     }
     $fp = fopen($filename, 'rb');
     return $fp;
 }
 /**
  * checks php internal upload error codes
  * @param string $filename
  * @return boolean $res 
  */
 public static function checkUploadNative($file)
 {
     $upload_return_code = $file['error'];
     if ($upload_return_code != 0) {
         self::$errors[] = upload::getNativeErrorMessage($upload_return_code);
         return false;
     }
     return true;
 }
Exemple #3
0
 /**
  * sets a file field with info about max file size
  * @param string $filename 
  * @param int $max_bytes
  * @param array $options
  */
 public static function fileWithLabel($filename, $max_bytes, $options = array())
 {
     $bytes = upload::getNativeMaxUpload();
     if ($max_bytes < $bytes) {
         $bytes = $max_bytes;
     }
     self::hidden('MAX_FILE_SIZE', $bytes);
     $label = lang::translate('Max size per file') . ". ";
     $size = upload::bytesToGreek($bytes);
     $label .= $size;
     if (isset($options['multiple'])) {
         $max_files = ini_get('max_file_uploads');
         $label .= "<br />";
         $label .= lang::translate('Max number of files: <span class="notranslate">{MAX_FILES}</span>', array('MAX_FILES' => $max_files));
     } else {
         $label .= "<br />";
         $label .= lang::translate('Only one file at a time');
     }
     self::label($filename, $label);
     self::file($filename, $options);
 }