/** * Creates a directory on the filesystem and returns an object representing it * * The directory creation is done recursively, so if any of the parent * directories do not exist, they will be created. * * This operation will be reverted by a filesystem transaction being rolled back. * * @throws fValidationException When no directory was specified, or the directory already exists * * @param string $directory The path to the new directory * @param numeric $mode The mode (permissions) to use when creating the directory. This should be an octal number (requires a leading zero). This has no effect on the Windows platform. * @return fDirectory */ public static function create($directory, $mode = 0777) { if (empty($directory)) { throw new fValidationException('No directory name was specified'); } if (file_exists($directory)) { throw new fValidationException('The directory specified, %s, already exists', $directory); } $parent_directory = fFilesystem::getPathInfo($directory, 'dirname'); if (!file_exists($parent_directory)) { fDirectory::create($parent_directory, $mode); } if (!is_writable($parent_directory)) { throw new fEnvironmentException('The directory specified, %s, is inside of a directory that is not writable', $directory); } mkdir($directory, $mode); $directory = new fDirectory($directory); fFilesystem::recordCreate($directory); return $directory; }
/** * 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; }
//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
} 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(); } } }
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()); }