Exemplo n.º 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 ') . bytes::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;
 }
 protected function uploadImage($url)
 {
     // Array ( [name] => Angus_cattle_18.jpg [type] => image/jpeg [tmp_name] => /tmp/php5lPQZT [error] => 0 [size] => 52162 )
     $ary = [];
     $name = file::getFilename($url) . "." . file::getExtension($url);
     $ary['name'] = $name;
     $ary['abstract'] = file::getFilename($url);
     $ary['type'] = file::getMime($url);
     $ary['tmp_name'] = $url;
     $ary['error'] = 0;
     $ary['size'] = 0;
     $i = new \modules\image\uploadBlob();
     $res = $i->insertFileDirect($ary, $this->reference, $this->parentId, $this->userId);
     if ($res) {
         $id = q::lastInsertId();
         $row = $i->getSingleFileInfo($id);
         return $i->getFullWebPath($row);
     } else {
         log::error("Could not upload image: {$name}");
         return false;
     }
 }
Exemplo n.º 3
0
    $str = file_get_contents('tmp/.database.sql');
    file_put_contents('.database.sql', $str);
    chmod('.database.sql', 0777);
    // And mount again
    Phar::mount('config/config.ini', '.config.ini');
    Phar::mount('sqlite/database.sql', '.database.sql');
}
if (php_sapi_name() == 'cli-server') {
    $info = parse_url($_SERVER['REQUEST_URI']);
    $file = $info['path'];
    if (file_exists("./{$info['path']}") && $info['path'] != '/') {
        $full = __DIR__ . "{$file}";
        if (!file_exists($full) or is_dir($full)) {
            echo "Is dir. Or does not exists";
            return false;
        }
        $mime = file::getMime($full);
        if ($mime) {
            if ($mime == 'text/x-php') {
                return false;
            }
            http::cacheHeaders();
            header("Content-Type: {$mime}");
            readfile($full);
        }
    } else {
        include "index.php";
    }
}
__halt_compiler();
Exemplo n.º 4
0
 /**
  * method for checking allowed mime types
  * @param string $filename the filename to check
  * @return boolean $res
  */
 public static function checkAllowedMime($file)
 {
     $type = file::getMime($file['tmp_name']);
     if (!in_array($type, self::$options['allow_mime'])) {
         $message = lang::translate('Mime type is not allowed. ');
         $message .= lang::translate('These mime types are allowed ') . MENU_SUB_SEPARATOR_SEC;
         $message .= self::getMimeAsString(self::$options['allow_mime']);
         self::$errors[] = $message;
         return false;
     }
     return true;
 }
Exemplo n.º 5
0
    $path = "..";
    include '../vendor/autoload.php';
}
conf::setMainIni('base_path', $path);
// Set real path
$real = realpath($path);
// PAth to current request
$info = parse_url($_SERVER['REQUEST_URI']);
// Does htdocs dir exists
if (file_exists($real . "/htdocs")) {
    $real .= "/htdocs" . "/{$info['path']}";
}
// Get full requst path
if (file_exists($real) && $info['path'] != '/') {
    //echo $real; die;
    $mime = file::getMime($real);
    //die;
    if ($mime) {
        if ($mime == 'text/x-php') {
            return false;
        }
        http::cacheHeaders();
        header("Content-Type: {$mime}");
        readfile($real);
    }
    die;
    //return false;
} else {
    $boot = new boot();
    $boot->run();
    return true;