public static function isValid($value, array $options = null, &$message = null) { if (!parent::isValid($value, $options, $message)) { return false; } if (static::isEmpty($value)) { return true; } $path = $value[static::PATH_KEY]; $name = $value[static::NAME_KEY]; $valid_mimes = array('image/gif', 'image/jpeg', 'image/png', 'image/bmp'); if (!in_array(static::getMimeType(static::getSystemPath($path), $name), $valid_mimes)) { $message = 'Unsupported image type.'; return false; } return true; }
/** * Associate an unsaved (new) File record with this Item. * * These File records will not be persisted in the database until the item * is saved or saveFiles() is invoked. * * @see Item::saveFiles() * @param File $file */ public function addFile(File $file) { if ($file->exists()) { throw new Omeka_Record_Exception(__("Cannot add an existing file to an item!")); } if (!$file->isValid()) { throw new Omeka_Record_Exception(__("File must be valid before it can be associated with an item!")); } $this->_files[] = $file; }
chmod($upload_file, 0644); } if (filesize($upload_file) == 0) { logError("File is empty."); exit; } if (!scanFile($upload_file)) { rename($upload_file, $upload_file . "-virus"); logError("File did not pass the virus scan."); exit; } $fd = fopen("/tmp/upload.log", "a"); fwrite($fd, "Upload: " . serialize($_FILES) . " with " . serialize($_POST) . "\n"); fclose($fd); print_r($_FILES); $file = new File(); $file->byPath($upload_file); if ($file->isValid()) { $file->incrementShrinks(); } else { $file->path = $upload_file; $file->tag = randomTag(); $file->params['name'] = preg_replace(',[^a-zA-Z0-9_:;!@#$%^+=.~-],', '', $f['name']); $file->params['content_type'] = $f['type']; $file->params['size'] = filesize($upload_file); $file->creator = new Creator($_SERVER["REMOTE_ADDR"], $_SESSION["acct_auth"] ? $_SESSION["acct_official"] : null); $file->store(); } $sth = getDB()->prepare("INSERT INTO upload_tracking (upload_id,file_id,error) VALUES (?,?,'f')"); $sth->execute(array($_POST["UPLOAD_IDENTIFIER"], $file->id)); }
<?php //Imports require_once 'session.php'; require_once 'db/db_conn.php'; require_once 'db/INSERT.php'; require_once 'db/UPDATE.php'; require_once 'classes/Correspondent.php'; require_once 'classes/File.php'; $ADK_FILE = new File(); if (!$ADK_FILE->isValid()) { header('Location: ../profile?e=' . $ADK_FILE->err); exit; } $ADK_FILE->populate(); $con = connect_db(); $ADK_CORRESPONDENT = new Correspondent(); $ADK_CORRESPONDENT->id = intval($_SESSION['ADK_USER_ID']); $ADK_FILES = new Files(); $ADK_FILES->files[0] = $ADK_FILE; $ADK_FILES->save($con); $ADK_CORRESPONDENT->photoid = $ADK_FILES->fileIDs[0]; $ADK_CORRESPONDENT->updatePhotoID($con); $con->close(); header('Location: ../hikers');
<?php /* This file is part of the Filebin package. Copyright (c) 2003-2009, Stephen Olesen All rights reserved. More information is available at http://filebin.ca/ */ require "template.inc.php"; require "filebin.inc.php"; $tag = $_GET["tag"]; $path = substr($_GET["path"], 1); $f = new File(); $f->byTag($tag); if ($f->isValid()) { $z = new ZipArchive(); if ($z->open($f->path) === TRUE) { if (substr($path, -1) == '/' || $path == "") { for ($i = 0; $i < $z->numFiles; $i++) { $s = $z->statIndex($i); if ($path == "" || substr_compare($path, $s['name'], 0, strlen($path), true) == 0 && $path != $s['name']) { $arr[] = $s['name']; } } asort($arr); foreach ($arr as $n) { print '<a href="http://filebin.ca/view/' . $tag . '/' . $n . '">' . $n . '</a><br />'; } } else { if (preg_match('/\\.jpe?g/i', $path)) { header("Content-Type: image/jpeg");