/** * Moves an uploaded file from the temp directory to a permanent location * * @throws fValidationException When `$directory` is somehow invalid or ::validate() thows an exception * * @param string|fDirectory $directory The directory to upload the file to * @param string $field The file upload field to get the file from * @param mixed $index If the field was an array file upload field, upload the file corresponding to this index * @return fFile|NULL An fFile (or fImage) object, or `NULL` if no file was uploaded */ public function move($directory, $field, $index = NULL) { if (!is_object($directory)) { $directory = new fDirectory($directory); } if (!$directory->isWritable()) { throw new fProgrammerException('The directory specified, %s, is not writable', $directory->getPath()); } if (!self::check($field)) { throw new fProgrammerException('The field specified, %s, does not appear to be a file upload field', $field); } $file_array = $this->extractFileUploadArray($field, $index); $error = $this->validateField($file_array); if ($error) { throw new fValidationException($error); } // This will only ever be true if the file is optional if ($file_array['name'] == '' || $file_array['tmp_name'] == '' || $file_array['size'] == 0) { return NULL; } $file_name = fFilesystem::makeURLSafe($file_array['name']); $file_name = $directory->getPath() . $file_name; if (!$this->enable_overwrite) { $file_name = fFilesystem::makeUniqueName($file_name); } if (!move_uploaded_file($file_array['tmp_name'], $file_name)) { throw new fEnvironmentException('There was an error moving the uploaded file'); } if (!chmod($file_name, 0644)) { throw new fEnvironmentException('Unable to change permissions on the uploaded file'); } return fFilesystem::createObject($file_name); }
<?php include '../inc/init.php'; $term = fRequest::get('term', 'string'); if ($GLOBALS['PRIMARY_SOURCE'] == 'GANGLIA') { if ($GLOBALS['GANGLIA_URL'] != '') { $json = file_get_contents($GLOBALS['GANGLIA_URL'] . '/tattle_autocomplete.php?term=' . $term); print $json; } } else { $path = str_replace('.', '/', fRequest::get('term', 'string')); $return_arr = array(); if ($GLOBALS['GRAPHITE_AUTOCOMPLETE_RECURSIVE'] == true) { $dir = new fDirectory($GLOBALS['WHISPER_DIR']); $directories = $dir->scanRecursive($path . '*'); } else { $searchPattern = "*"; if (!file_exists($GLOBALS['WHISPER_DIR'] . $path)) { $dirParts = explode("/", $path); $searchPattern = array_pop($dirParts) . $searchPattern; $path = implode("/", $dirParts); } $dir = new fDirectory($GLOBALS['WHISPER_DIR'] . $path); $directories = $dir->scan($searchPattern); } foreach ($directories as $directory) { $return_arr[] = array('value' => str_replace('.wsp', '', str_replace('/', '.', str_replace($GLOBALS['WHISPER_DIR'], '', $directory->getPath())))); } print json_encode($return_arr); }
/** * Copies a file from the filesystem to the file upload directory and sets it as the file for the specified column * * This method will perform the fImage calls defined for the column. * * @internal * * @param fActiveRecord $object The fActiveRecord instance * @param array &$values The current values * @param array &$old_values The old values * @param array &$related_records Any records related to this record * @param array &$cache The cache array for the record * @param string $method_name The method that was called * @param array $parameters The parameters passed to the method * @return fActiveRecord The record object, to allow for method chaining */ public static function set($object, &$values, &$old_values, &$related_records, &$cache, $method_name, $parameters) { $class = get_class($object); list($action, $column) = fORM::parseMethod($method_name); $doc_root = realpath($_SERVER['DOCUMENT_ROOT']); if (!array_key_exists(0, $parameters)) { throw new fProgrammerException('The method %s requires exactly one parameter', $method_name . '()'); } $file_path = $parameters[0]; // Handle objects being passed in if ($file_path instanceof fFile) { $file_path = $file_path->getPath(); } elseif (is_object($file_path) && is_callable(array($file_path, '__toString'))) { $file_path = $file_path->__toString(); } elseif (is_object($file_path)) { $file_path = (string) $file_path; } if ($file_path !== NULL && $file_path !== '' && $file_path !== FALSE) { if (!$file_path || !file_exists($file_path) && !file_exists($doc_root . $file_path)) { throw new fEnvironmentException('The file specified, %s, does not exist. This may indicate a missing enctype="multipart/form-data" attribute in form tag.', $file_path); } if (!file_exists($file_path) && file_exists($doc_root . $file_path)) { $file_path = $doc_root . $file_path; } if (is_dir($file_path)) { throw new fProgrammerException('The file specified, %s, is not a file but a directory', $file_path); } $upload_dir = self::$file_upload_columns[$class][$column]; try { $temp_dir = new fDirectory($upload_dir->getPath() . self::TEMP_DIRECTORY . DIRECTORY_SEPARATOR); } catch (fValidationException $e) { $temp_dir = fDirectory::create($upload_dir->getPath() . self::TEMP_DIRECTORY . DIRECTORY_SEPARATOR); } $file = fFilesystem::createObject($file_path); $new_file = $file->duplicate($temp_dir); } else { $new_file = NULL; } fActiveRecord::assign($values, $old_values, $column, $new_file); // Perform column inheritance if (!empty(self::$column_inheritence[$class][$column])) { foreach (self::$column_inheritence[$class][$column] as $other_column) { self::set($object, $values, $old_values, $related_records, $cache, 'set' . fGrammar::camelize($other_column, TRUE), array($file)); } } if ($new_file) { self::processImage($class, $column, $new_file); } return $object; }
/** * Renames the current directory * * This operation will NOT be performed until the filesystem transaction * has been committed, if a transaction is in progress. Any non-Flourish * code (PHP or system) will still see this directory (and all contained * files/dirs) as existing with the old paths until that point. * * @param string $new_dirname The new full path to the directory or a new name in the current parent directory * @param boolean $overwrite If the new dirname already exists, TRUE will cause the file to be overwritten, FALSE will cause the new filename to change * @return void */ public function rename($new_dirname, $overwrite) { $this->tossIfDeleted(); if (!$this->getParent()->isWritable()) { throw new fEnvironmentException('The directory, %s, can not be renamed because the directory containing it is not writable', $this->directory); } // If the dirname does not contain any folder traversal, rename the dir in the current parent directory if (preg_match('#^[^/\\\\]+$#D', $new_dirname)) { $new_dirname = $this->getParent()->getPath() . $new_dirname; } $info = fFilesystem::getPathInfo($new_dirname); if (!file_exists($info['dirname'])) { throw new fProgrammerException('The new directory name specified, %s, is inside of a directory that does not exist', $new_dirname); } if (file_exists($new_dirname)) { if (!is_writable($new_dirname)) { throw new fEnvironmentException('The new directory name specified, %s, already exists, but is not writable', $new_dirname); } if (!$overwrite) { $new_dirname = fFilesystem::makeUniqueName($new_dirname); } } else { $parent_dir = new fDirectory($info['dirname']); if (!$parent_dir->isWritable()) { throw new fEnvironmentException('The new directory name specified, %s, is inside of a directory that is not writable', $new_dirname); } } rename($this->directory, $new_dirname); // Make the dirname absolute $new_dirname = fDirectory::makeCanonical(realpath($new_dirname)); // Allow filesystem transactions if (fFilesystem::isInsideTransaction()) { fFilesystem::rename($this->directory, $new_dirname); } fFilesystem::updateFilenameMapForDirectory($this->directory, $new_dirname); }
/** * Sets the path to store session files in * * This method should always be called with a non-standard directory * whenever ::setLength() is called to ensure that another site on the * server does not garbage collect the session files for this site. * * Standard session directories usually include `/tmp` and `/var/tmp`. * * @param string|fDirectory $directory The directory to store session files in * @return void */ public static function setPath($directory) { if (self::$open || isset($_SESSION)) { throw new fProgrammerException('%1$s must be called before any of %2$s, %3$s, %4$s, %5$s, %6$s, %7$s or %8$s', __CLASS__ . '::setPath()', __CLASS__ . '::add()', __CLASS__ . '::clear()', __CLASS__ . '::enablePersistence()', __CLASS__ . '::get()', __CLASS__ . '::open()', __CLASS__ . '::set()', 'session_start()'); } if (!$directory instanceof fDirectory) { $directory = new fDirectory($directory); } if (!$directory->isWritable()) { throw new fEnvironmentException('The directory specified, %s, is not writable', $directory->getPath()); } session_save_path($directory->getPath()); }
/** * Renames the current file * * If the filename already exists and the overwrite flag is set to false, * a new filename will be created. * * This operation will be reverted if a filesystem transaction is in * progress and is later rolled back. * * @param string $new_filename The new full path to the file or a new filename in the current directory * @param boolean $overwrite If the new filename already exists, `TRUE` will cause the file to be overwritten, `FALSE` will cause the new filename to change * @return fFile The file object, to allow for method chaining */ public function rename($new_filename, $overwrite) { $this->tossIfDeleted(); if (!$this->getParent()->isWritable()) { throw new fEnvironmentException('The file, %s, can not be renamed because the directory containing it is not writable', $this->file); } // If the filename does not contain any folder traversal, rename the file in the current directory if (preg_match('#^[^/\\\\]+$#D', $new_filename)) { $new_filename = $this->getParent()->getPath() . $new_filename; } $info = fFilesystem::getPathInfo($new_filename); if (!file_exists($info['dirname'])) { throw new fProgrammerException('The new filename specified, %s, is inside of a directory that does not exist', $new_filename); } // Make the filename absolute $new_filename = fDirectory::makeCanonical(realpath($info['dirname'])) . $info['basename']; if ($this->file == $new_filename && $overwrite) { return $this; } if (file_exists($new_filename) && !$overwrite) { $new_filename = fFilesystem::makeUniqueName($new_filename); } if (file_exists($new_filename)) { if (!is_writable($new_filename)) { throw new fEnvironmentException('The new filename specified, %s, already exists, but is not writable', $new_filename); } if (fFilesystem::isInsideTransaction()) { fFilesystem::recordWrite(new fFile($new_filename)); } // Windows requires that the existing file be deleted before being replaced unlink($new_filename); } else { $new_dir = new fDirectory($info['dirname']); if (!$new_dir->isWritable()) { throw new fEnvironmentException('The new filename specified, %s, is inside of a directory that is not writable', $new_filename); } } rename($this->file, $new_filename); // Allow filesystem transactions if (fFilesystem::isInsideTransaction()) { fFilesystem::recordRename($this->file, $new_filename); } fFilesystem::updateFilenameMap($this->file, $new_filename); return $this; }
/** * Converts PHP short tags to long tags when short tags are turned off * * Please note that this only affects PHP files that are **directly** * evaluated with ::place() or ::inject(). It will not affect PHP files that * have been evaluated via `include` or `require` statements inside of the * directly evaluated PHP files. * * This functionality will be inherited by all child fTemplating objects * that do not have their own explicit short tag settings. * * @param string $mode The compilation mode - `'development'` means that file modification times will be checked on each load, `'production'` means that the cache files will only be regenerated when missing * @param fDirectory|string $cache_directory The directory to cache the compiled files into - this directory should not be accessible from the web * @return void */ public function enablePHPShortTags($mode, $cache_directory) { // This does not need to be enabled if short tags are on if (ini_get('short_open_tag') && strtolower(ini_get('short_open_tag')) != 'off') { return; } $valid_modes = array('development', 'production'); if (!in_array($mode, $valid_modes)) { throw new fProgrammerException('The mode specified, %1$s, is invalid. Must be one of: %2$s.', $mode, join(', ', $valid_modes)); } $cache_directory = $cache_directory instanceof fDirectory ? $cache_directory->getPath() : $cache_directory; if (!is_writable($cache_directory)) { throw new fEnvironmentException('The cache directory specified, %s, is not writable', $cache_directory); } $this->short_tag_mode = $mode; $this->short_tag_directory = fDirectory::makeCanonical($cache_directory); }
} else { if ($_POST['type'] == "option") { $selectedOption = $_POST['input'] == "Active" ? 1 : 0; echo "<select>"; Status::printOption($selectedOption); echo "</select>"; } else { if ($_POST['type'] == "lastCode") { $counter = Inv_item::findByClassificationCode($_POST['classific']); echo sprintf("%03d", $counter->count() + 1); } else { if ($_POST['type'] == "upload") { try { $uploadDirectory = new fDirectory('../storage/image/' . $_POST['hiddenId']); } catch (fExpectedException $e) { $uploadDirectory = fDirectory::create('../storage/image/' . $_POST['hiddenId']); } try { $uploader = new fUpload(); $uploader->setMIMETypes(array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'), 'The file uploaded is not an image'); $uploader->enableOverwrite(); $file = $uploader->move($uploadDirectory, 'file'); $inv_item = new Inv_item($_POST['hiddenId']); $inv_item->setImageUrl('storage/image/' . $_POST['hiddenId'] . '/' . $file->getFilename()); $inv_item->store(); echo "Image uploaded"; } catch (fExpectedException $e) { echo $e->printMessage(); } } }
/** * Moves an uploaded file from the temp directory to a permanent location * * @throws fValidationException When `$directory` is somehow invalid or ::validate() thows an exception * * @param string|fDirectory $directory The directory to upload the file to * @param string $field The file upload field to get the file from * @param integer $index If the field was an array file upload field, upload the file corresponding to this index * @return fFile An fFile (or fImage) object */ public function move($directory, $field, $index = NULL, $param_filename = NULL) { if (!is_object($directory)) { $directory = new fDirectory($directory); } if (!$directory->isWritable()) { throw new fProgrammerException('The directory specified, %s, is not writable', $directory->getPath()); } if (!self::check($field)) { throw new fProgrammerException('The field specified, %s, does not appear to be a file upload field', $field); } $file_array = $this->validate($field, $index); $file_name = fFilesystem::makeURLSafe($param_filename == NULL ? $file_array['name'] : $param_filename); $file_name = $directory->getPath() . $file_name; if (!$this->enable_overwrite) { $file_name = fFilesystem::makeUniqueName($file_name); } if (!move_uploaded_file($file_array['tmp_name'], $file_name)) { throw new fEnvironmentException('There was an error moving the uploaded file'); } if (!chmod($file_name, 0644)) { throw new fEnvironmentException('Unable to change permissions on the uploaded file'); } return fFilesystem::createObject($file_name); }
/** * Sets a custom directory to use for the ImageMagick temporary files * * @param string $temp_dir The directory to use for the ImageMagick temp dir * @return void */ public static function setImageMagickTempDir($temp_dir) { $temp_dir = new fDirectory($temp_dir); if (!$temp_dir->isWritable()) { throw new fEnvironmentException('The ImageMagick temp directory specified, %s, does not appear to be writable', $temp_dir->getPath()); } self::$imagemagick_temp_dir = $temp_dir->getPath(); }
//Pozivanje validacijske klase $v = $app->validation; //Validacija polja iz forme $v->validate(['img_title' => [$img_title, 'required|min(4)'], 'picture' => [$_FILES['picture']['name'], 'required']]); //Ako je validacija prosla uspijesno if ($v->passes()) { $image = $app->image; //Dohvatanje Image klase sa start.php fajla iz Slim2 containera $allowedMIME = ['jpg', 'jpeg', 'png']; //Dozvoljeni niz ekstenzija za upload //Folder za smijestanje korisnickih slika od profila $userDir = INC_ROOT . "/app/uploads/profile_img/{$app->auth->username}/"; //Provjera da li korisnicki folder za profilena slike postoji if (!is_dir($userDir)) { //Stvaranje korisnickog foldera za profilne slike koji ce se zvati kao njihovo username $userUploadFolder = fDirectory::create($userDir); } //Prebacujemo putanju do korisnickog upload foldera u novu var. $userUploadFolder = $userDir; //Namjestanje dozvoljenog niza estenzija,dozvoljene velicine fajla,dozvoljene dizmenzije slike,i smijestanje u profile_img folder. $image->setMime($allowedMIME)->setSize(1000, 1048576)->setDimension(500, 500)->setLocation($userUploadFolder); //Provjera da li uplodovana slika postoji if ($image['picture']) { //Izvrsavanje uploada slike $upload = $image->upload(); //Provjera da li je slika ucitana na zeljenu lokaciju if ($upload) { //Dohvatanje stare korisnikove slike i njeno brisanje it uploads/profile_img foldera //Sistemska putanje do profilene slike korisnika //(C:/xampp/htdocs/Vijezbe/Church/app/uploads/profile_img/155e339180caf9_gokqijelpmfhn.jpeg) //Zato sto file_exists() f. uzima sistemsku putanju,a ne url putanju do file da bi se izvrsila
<?php include '../inc/init.php'; $term = fRequest::get('term', 'string'); if ($GLOBALS['PRIMARY_SOURCE'] == 'GANGLIA') { if ($GLOBALS['GANGLIA_URL'] != '') { $json = file_get_contents($GLOBALS['GANGLIA_URL'] . '/tattle_autocomplete.php?term=' . $term); print $json; } } else { $dir = new fDirectory($GLOBALS['WHISPER_DIR']); $path = str_replace('.', '/', fRequest::get('term', 'string')); $directories = $dir->scanRecursive($path . '*'); $return_arr = array(); foreach ($directories as $directory) { $return_arr[] = array('value' => str_replace('.wsp', '', str_replace('/', '.', str_replace($GLOBALS['WHISPER_DIR'], '', $directory->getPath())))); } print json_encode($return_arr); }
public function testMove() { $dir = fDirectory::create('output/fDirectory2/'); $dir->move('output/fDirectory/', TRUE); $this->assertEquals('fDirectory2', $dir->getName()); $this->assertEquals(str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'] . '/output/fDirectory/'), $dir->getParent()->getPath()); }
$sql = "CREATE TABLE `patch_history` ( `num` smallint(5) unsigned NOT NULL) ENGINE='MyISAM' COLLATE 'utf8_unicode_ci'"; $db->query($sql); $sql = "ALTER TABLE `patch_history` ADD PRIMARY KEY `num` (`num`)"; $db->query($sql); $sql = "INSERT INTO `patch_history` SET `num` = 0"; $db->query($sql); } // Get the last patch level $sql = "SELECT MAX(num) AS num FROM patch_history"; $row = $db->query($sql)->fetchRow(); $num = (int) $row['num']; // Next patch to install $next = $num + 1; echo "Current patch level: {$num}.<br>"; // Get the highest patch level available $patch_dir = new fDirectory(DOC_ROOT . '/db'); $patch_files = $patch_dir->scan('patch*.sql'); foreach ($patch_files as $file) { // Get patch number from filename preg_match('/patch([0-9]+).sql/', $file->getName(), $matches); $patch_num = $matches[1]; // If it's at the right level, run it. if ($patch_num >= $next) { echo "Running " . $file->getName() . "... "; $contents = $file->read(); try { $db->query($contents); $db->query("INSERT INTO patch_history SET num = %i ON DUPLICATE KEY UPDATE num = VALUES(num);", $patch_num); echo "OK!<br>"; } catch (fException $e) { echo "Error: " . $e->getMessage() . "<br>";