copy() public static method

Copy a file to a new location.
public static copy ( string $path, string $target ) : boolean
$path string
$target string
return boolean
Example #1
0
 protected function copyFile($file, $target)
 {
     if (!\File::exists($target)) {
         return \File::copy($file, $target);
     }
     return false;
 }
 /**
  * Recursively copy a folder and its contents
  * http://aidan.dotgeek.org/lib/?file=function.copyr.php
  *
  * @author      Aidan Lister <*****@*****.**>
  * @version     1.0.1
  * @param       string   $source    Source path
  * @param       string   $dest      Destination path
  * @return      bool     Returns TRUE on success, FALSE on failure
  */
 function copyDir($source, $dest)
 {
     clearstatcache();
     // Simple copy for a file
     if (is_file($source)) {
         return File::copy($source, $dest);
     }
     // Make destination directory
     if (!File::isDir($dest)) {
         File::createDir($dest);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         if ($dest !== "{$source}/{$entry}") {
             MyFile::copyDir("{$source}/{$entry}", "{$dest}/{$entry}");
         }
     }
     // Clean up
     $dir->close();
     return true;
 }
Example #3
0
 /**
  * Copies the directory within all files to the destination.
  * @param string $destination The destination path.
  * @param boolean $overwrite If already exists overwrite it or not.
  * @param boolean $mt Keep the modification time of the directory or not.
  * @throws FileException If failed to copy the directory.
  * @return Directory The copied directory.
  */
 public function copy($destination, $overwrite = false, $mt = false)
 {
     if (dirname($destination) == ".") {
         $destination = $this->getDirectory() . DS . $destination;
     }
     $destination = $this->preparePath($destination, false);
     if (strcmp(substr($destination, -1), DS) == 0) {
         $destination .= $this->getName();
     }
     foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->pathAbsolute, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
         $path = $iterator->getSubPathName();
         $dest = $destination . DS . $path;
         $d = Config::$root . $dest;
         if ($item->isDir()) {
             if (!file_exists($d) && !mkdir($d, $this->permission, true)) {
                 throw new FileException(array("Directory '%s' not exists.", $dest));
             }
             if ($mt) {
                 $filemtime = $item->getMTime();
                 @touch($d, $filemtime);
             }
         } else {
             $file = new File($this->path . DS . $path);
             $file->copy($dest, $overwrite, $mt);
         }
     }
     return new Directory($destination);
 }
Example #4
0
 /**
  * Copy directory to another directory location
  *
  * @param \Drone\Filesystem\Directory $directory (directory object with copy location)
  * @return boolean
  */
 public function copy(\Drone\Filesystem\Directory $directory, $chmod = 0644)
 {
     if (!$this->__isDir()) {
         return false;
     }
     if (!$directory->create($chmod)) {
         $this->error = 'Failed to create new directory \'' . $directory->getPath() . '\'';
         return false;
     }
     foreach ($this->read(false, true) as $asset) {
         if ($asset['type'] === 'dir') {
             $dir = new Directory($this->_path . $asset['name'], false);
             if (!$dir->copy(new Directory($directory->getPath() . $asset['name'], false), $chmod)) {
                 $this->error = 'Failed to create new subdirectory \'' . $dir->getPath() . '\' (' . $dir->error . '), try elevated chmod';
                 return false;
             }
         } else {
             $file = new File($this->_path . $asset['name'], false);
             if (!$file->copy(new File($directory->getPath() . $asset['name'], false), $chmod)) {
                 $this->error = 'Failed to create new file \'' . $file->getPath() . '\' (' . $file->error . '), try elevated chmod';
                 return false;
             }
         }
     }
     return true;
 }
Example #5
0
 function execute()
 {
     $file_or_folder = $this->file_or_folder;
     if (self::$dummy_mode) {
         echo "Adding : " . $file_or_folder . "<br />";
         return;
     }
     $root_dir_path = self::$root_dir->getPath();
     $file_or_folder = str_replace("\\", "/", $file_or_folder);
     $file_list = array();
     //se finisce con lo slash è una directory
     if (substr($file_or_folder, strlen($file_or_folder) - 1, 1) == "/") {
         //creo la cartella
         $target_dir = new Dir(DS . $root_dir_path . $file_or_folder);
         $target_dir->touch();
         $source_dir = new Dir($this->module_dir->getPath() . $file_or_folder);
         foreach ($source_dir->listFiles() as $elem) {
             if ($elem->isDir()) {
                 $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getName() . DS));
             } else {
                 $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getFilename()));
             }
         }
     } else {
         $source_file = new File($this->module_dir->getPath() . $file_or_folder);
         $target_file = new File($root_dir_path . $file_or_folder);
         $target_dir = $target_file->getDirectory();
         $target_dir->touch();
         $source_file->copy($target_dir);
         $file_list[] = $target_dir->newFile($source_file->getFilename())->getPath();
     }
     return $file_list;
 }
Example #6
0
 /**
  * copies files/directories recursively
  * @param  string  $source    from
  * @param  string  $dest      to
  * @param  boolean $overwrite overwrite existing file
  * @return void             
  */
 public static function copy($source, $dest, $overwrite = false)
 {
     //Lets just make sure our new folder is already created. Alright so its not efficient to check each time... bite me
     if (is_file($dest)) {
         copy($source, $dest);
         return;
     }
     if (!is_dir($dest)) {
         mkdir($dest);
     }
     $objects = scandir($source);
     foreach ($objects as $object) {
         if ($object != '.' && $object != '..') {
             $path = $source . '/' . $object;
             if (is_file($path)) {
                 if (!is_file($dest . '/' . $object) || $overwrite) {
                     if (!@copy($path, $dest . '/' . $object)) {
                         die('File (' . $path . ') could not be copied, likely a permissions problem.');
                     }
                 }
             } elseif (is_dir($path)) {
                 if (!is_dir($dest . '/' . $object)) {
                     mkdir($dest . '/' . $object);
                 }
                 // make subdirectory before subdirectory is copied
                 File::copy($path, $dest . '/' . $object, $overwrite);
                 //recurse!
             }
         }
     }
 }
Example #7
0
 /**
  * Create a copy of the file
  *
  * @param   string  $from  The full path of the file to copy from
  * @param   string  $to    The full path of the file that will hold the copy
  *
  * @return  boolean  True on success
  */
 public function copy($from, $to)
 {
     $ret = $this->fileAdapter->copy($from, $to);
     if (!$ret && is_object($this->abstractionAdapter)) {
         return $this->abstractionAdapter->copy($from, $to);
     }
     return $ret;
 }
Example #8
0
 function replace($path)
 {
     $F = new File($path);
     $md5 = $F->md5();
     $this->path = appPATH . 'qg/file/' . $md5;
     $F->copy($this->path);
     $this->setVs(array('name' => $F->basename(), 'mime' => $F->mime(), 'text' => $F->getText(), 'md5' => $F->md5(), 'size' => $F->size()));
 }
 /**
  * Seeds with a randomly generated Project
  *
  * @param $iteration String: the current iteration
  * @return mixed
  */
 public function seed($iteration)
 {
     factory(Project::class, 1)->create(['author' => $this->faker->userName, 'title' => preg_replace('/[^a-z0-9 ]+/i', "", $this->faker->realText(32)), 'description' => $this->faker->realText(30), 'body' => $this->faker->realText()]);
     $newestID = DB::table('projects')->orderBy('created_at', 'desc')->first()->id;
     //Get the project that was just created's id
     $imagePath = 'public/images/projects/' . 'product' . $newestID . '.jpg';
     File::copy($this->images[$iteration % 6], $imagePath);
 }
Example #10
0
 protected function copyFiles()
 {
     $files = \File::files(base_path());
     foreach ($files as $file) {
         $path = str_replace(base_path(), '', $file);
         \File::copy($file, base_path() . '/backup/' . $this->timestamp . '/' . $path);
     }
 }
Example #11
0
 /**
  * Create the config file copying the config.php.install file
  */
 private function _createConfigFile()
 {
     $destinationPath = App::pluginPath('Gallery') . 'config' . DS . 'config.php';
     if (!file_exists($destinationPath)) {
         $configFile = new File(App::pluginPath('Gallery') . 'config' . DS . 'config.php.install');
         $configFile->copy($destinationPath);
     }
 }
 public function testRemoveFile()
 {
     $fileName = $this->destinationPath . 'avatar.png';
     $thumbName = $this->destinationPath . 'thumb_avatar.png';
     $file = new File($this->originPath . 'avatar.png');
     $file->copy($fileName);
     $this->assertTrue($this->behavior->removeFile($this->model, $fileName));
 }
Example #13
0
 public function main()
 {
     $Folder = new Folder(dirname(dirname(dirname(__FILE__))) . DS . "features");
     $this->out("copy " . $Folder->pwd() . " to Cake Root...");
     $Folder->copy(array('to' => ROOT . DS . "features"));
     $File = new File(dirname(__FILE__) . DS . "behat.yml.default");
     $this->out("copy " . $File->name() . " to App/Config...");
     $File->copy(APP . DS . "Config" . DS . "behat.yml");
 }
Example #14
0
 /**
  * 產生輔翼系統更新會員資料檔案
  * 
  * @return string $dest
  */
 public function genFlapUpdateFile()
 {
     $file = __DIR__ . '/../../../../../storage/excel/example/updateFormat.xls';
     $dest = $this->getUpdateFilePath();
     if (!\File::copy($file, $dest)) {
         throw new \Exception('Could not copy file!');
     }
     return $this;
 }
Example #15
0
 public function getPicture($params = [])
 {
     $pic = __DIR__ . '/../../tests/files/temp.jpg';
     $params = array_merge(['name' => 'picture.jpg'], $params);
     if (!is_file($pic)) {
         File::copy(__DIR__ . '/../../tests/files/chrysanthemum.jpg', $pic);
     }
     return new UploadedFile($pic, $params['name'], 'image/jpeg', null, null, true);
 }
 private function copyImage($originalImage)
 {
     $explodedImage1 = explode('/', $originalImage);
     $image1 = end($explodedImage1);
     $imageName1 = Str::random(20) . time() . $image1;
     $image1path = $this->getImagesPath() . $imageName1;
     File::copy($originalImage, $image1path);
     return $imageName1;
 }
 public function admin_export($id = null)
 {
     if (!$id) {
         $this->notice('invalid');
     }
     $this->Template->recursive = -1;
     $template = $this->Template->read(array('name', 'description', 'author', 'header', 'footer'), $id);
     if (empty($template)) {
         $this->notice('invalid');
     }
     $pattern = "/src=[\\\"']?([^\\\"']?.*(png|jpg|gif|jpeg))[\\\"']?/i";
     preg_match_all($pattern, $template['Template']['header'], $images);
     $path = TMP . 'cache' . DS . 'newsletter' . DS . 'template' . DS . $template['Template']['name'];
     $Folder = new Folder($path, 0777);
     $slash = $Folder->correctSlashFor($path);
     App::import('File');
     App::import('Folder');
     $File = new File($path . DS . 'template.xml', true, 0777);
     $imageFiles = array();
     if (!empty($images[1])) {
         foreach ($images[1] as $img) {
             $img = str_replace('/', $slash, $img);
             $img = str_replace('\\', $slash . $slash, $img);
             $imageFiles[] = $img;
             if (is_file(APP . 'webroot' . $img)) {
                 $Folder->create(dirname($path . $img), 0777);
                 $File->path = APP . 'webroot' . $img;
                 $File->copy(dirname($path . $img) . DS . basename($img));
             }
         }
     }
     $xml['template']['name'] = 'Infinitas Newsletter Template';
     $xml['template']['generator'] = 'Infinitas Template Generator';
     $xml['template']['version'] = $this->version;
     $xml['template']['template'] = $template['Template']['name'];
     $xml['template']['description'] = $template['Template']['description'];
     $xml['template']['author'] = $template['Template']['author'];
     $xml['data']['header'] = $template['Template']['header'];
     $xml['data']['footer'] = $template['Template']['footer'];
     $xml['files']['images'] = $imageFiles;
     App::Import('Helper', 'Xml');
     $Xml = new XmlHelper();
     $File->path = $path . DS . 'template.xml';
     $File->write($Xml->serialize($xml));
     App::import('Vendor', 'Zip', array('file' => 'zip.php'));
     $Zip = new CreateZipFile();
     $Zip->zipDirectory($path, null);
     $File = new File($path . DS . 'template.zip', true, 0777);
     $File->write($Zip->getZippedfile());
     $this->view = 'Media';
     $params = array('id' => 'template.zip', 'name' => $template['Template']['name'], 'download' => true, 'extension' => 'zip', 'path' => $path . DS);
     $this->set($params);
     $Folder = new Folder($path);
     $Folder->read();
     $Folder->delete($path);
 }
Example #18
0
 /**
  * Create temporary file for upload test.
  *
  * @param string $fileName Temporary file name
  * @return void
  */
 public function createTmpFile($fileName)
 {
     //アップロードテストのためのテンポラリファイル生成
     $folder = new Folder();
     $folder->create(TMP . 'tests' . DS . 'files' . DS . 'tmp');
     $file = new File(APP . 'Plugin' . DS . 'Files' . DS . 'Test' . DS . 'Fixture' . DS . $fileName);
     $file->copy(TMP . 'tests' . DS . 'files' . DS . 'tmp' . DS . $fileName);
     $file->close();
     unset($folder, $file);
 }
 function perform()
 {
     $this->_fileContent = $this->_request->getValue("fileContent");
     // get a list with all the specific template files
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $templateFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
     if (!empty($this->_subFolderId)) {
         $templateFolder = $templateFolder . $this->_subFolderId . "/";
     }
     $backupFolder = $templateFolder . "backups/";
     if (!File::exists($backupFolder)) {
         File::createDir($backupFolder);
     }
     $fileName = $templateFolder . $this->_fileId;
     $backupFileName = $backupFolder . $this->_fileId . "_" . time();
     if (!File::copy($fileName, $backupFileName)) {
         if (empty($this->_subFolderId)) {
             $this->_view = new PluginBlogEditTemplateFileView($this->_blogInfo, $this->_templateId, $this->_fileId, $this->_backupId);
         } else {
             $this->_view = new PluginBlogEditSubFolderTemplateFileView($this->_blogInfo, $this->_templateId, $this->_subFolderId, $this->_fileId, $this->_backupId);
         }
         $this->_view->setErrorMessage($this->_locale->tr("error_backup_template_file"));
         $this->setCommonData();
         return false;
     }
     $file = new MyFile($fileName);
     if (!$file->isWritable()) {
         if (empty($this->_subFolderId)) {
             $this->_view = new PluginBlogEditTemplateFileView($this->_blogInfo, $this->_templateId, $this->_fileId, $this->_backupId);
         } else {
             $this->_view = new PluginBlogEditSubFolderTemplateFileView($this->_blogInfo, $this->_templateId, $this->_subFolderId, $this->_fileId, $this->_backupId);
         }
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_template_file"));
         $this->setCommonData();
         return false;
     }
     $fileContent = $file->writeFileContent($this->_fileContent);
     // if everything went ok...
     $this->_session->setValue("blogInfo", $this->_blogInfo);
     $this->saveSession();
     if (empty($this->_subFolderId)) {
         $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
     } else {
         $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
     }
     $this->_view->setSuccessMessage($this->_locale->tr("templateeditor_file_saved_ok"));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     return true;
 }
 /**
  * copy customized extension.yml, classes and templates to silverstripe project which should be availible as skelet
  */
 public static function add()
 {
     File::copy(Installer::getRootDirVendor() . static::getExtension(), Installer::getRootDirConfig());
     Installer::getComposerEvent()->getIO()->write(":: copied " . self::getConfigfile());
     foreach (static::getClasses() as $folder => $class) {
         File::copy(Installer::getRootDirVendor() . $class, Installer::getRootDirCode() . $folder . "/");
         Installer::getComposerEvent()->getIO()->write(":: added class {$class}");
     }
     foreach (static::getTemplates() as $folder => $template) {
         File::copy(Installer::getRootDirVendor() . $template, Installer::getRootDirTheme() . $folder . "/");
         Installer::getComposerEvent()->getIO()->write(":: added template {$template}");
     }
 }
Example #21
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user = User::create(['username' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt('admin')]);
     $user->isAdmin = 1;
     $user->save();
     \File::makeDirectory(public_path() . "/content/admin");
     \File::makeDirectory(public_path() . "/content/admin/photos/");
     $dest = public_path() . "/content/admin/photos/profile.png";
     $file = public_path() . "/img/profile.png";
     \File::copy($file, $dest);
     UserInfo::create(["user_id" => $user->id, "photo" => "/content/admin/photos/profile.png"]);
     //init Payment
     Payment::create(['stripe_publishable_key' => '', 'stripe_secret_key' => '', 'paypal_client_id' => '', 'paypal_secret' => '']);
 }
Example #22
0
 public static function add($f)
 {
     $foo = new Upload($f);
     if ($foo->uploaded) {
         $foo->Process(TMPFILES);
     }
     if ($foo->processed) {
         $fname = $foo->file_src_name_body;
         $fpath = TMPFILES . DS . $fname;
         $zip = new ZipArchive();
         $res = $zip->open(TMPFILES . DS . $foo->file_src_name);
         if ($res === TRUE) {
             $zip->extractTo($fpath . DS);
             $zip->close();
             $pack = json_decode(file_get_contents($fpath . DS . 'package.json'), true);
             if (count($pack['controllers']) > 0) {
                 foreach ($pack['controllers'] as $c) {
                     File::copy($fpath . DS . 'controllers' . DS . $c, CONTROLLERS . DS . $c);
                 }
             }
             if (count($pack['views']) > 0) {
                 foreach ($pack['views'] as $c) {
                     File::copy($fpath . DS . 'views' . DS . $c, VIEWS . DS . $c);
                 }
             }
             if (count($pack['langs']) > 0) {
                 foreach ($pack['langs'] as $c) {
                     File::copy($fpath . DS . 'lang' . DS . $c, LANGS . DS . $c);
                 }
             }
             if (count($pack['libs']) > 0) {
                 foreach ($pack['libs'] as $c) {
                     File::copy($fpath . DS . 'lib' . DS . $c, LIB . DS . $c);
                 }
             }
             if (count($pack['filters']) > 0) {
                 foreach ($pack['filters'] as $c) {
                     File::copy($fpath . DS . 'filters' . DS . $c, FILTER . DS . $c);
                 }
             }
             File::copy($fpath . DS . 'package.json', CONFPLUGINS . DS . $pack['name'] . '.json');
             File::copy($fpath . DS . 'routes.php', ROOT . DS . "routes" . DS . $pack['name'] . '.routes.php');
             File::removedir($fpath);
             File::remove(TMPFILES . DS . $foo->file_src_name);
         } else {
             return false;
         }
     }
     return true;
 }
Example #23
0
 public function insert($imageList, $newsletterID)
 {
     $db = MySQL::getInstance();
     $db->query("SELECT COUNT(*) FROM `newsletter_image` WHERE `NewsletterID` = " . $db->escape((int) $newsletterID));
     $position = $row = $db->fetchField() ? $row : 0;
     foreach ($imageList as $key => $image) {
         $position++;
         $db->query("INSERT INTO newsletter_image (NewsletterID, `File`, `Position`) VALUES (\n\t\t\t\t" . $db->escape((int) $newsletterID) . ",\n\t\t\t\t" . $db->escape($image) . ",\n\t\t\t\t" . $db->escape((int) $position) . "\n\t\t\t)");
         if (File::copy($image, 'thumb_' . $image, 'var/newsletter/gallery/')) {
             File::imageCrop('thumb_' . $image, 'var/newsletter/gallery/', 320, 240);
         }
         File::imageResize($image, 'var/newsletter/gallery/');
     }
 }
 function perform()
 {
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $templateFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
     if (!empty($this->_subFolderId)) {
         $templateFolder = $templateFolder . $this->_subFolderId . "/";
     }
     // Get template files according extension
     $templateFiles = $this->getTemplateFiles($templateFolder);
     foreach ($templateFiles as $file) {
         if ($file['name'] == $this->_newFileId) {
             if (empty($this->_subFolderId)) {
                 $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
             } else {
                 $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
             }
             $this->_view->setErrorMessage($this->_locale->tr("error_duplicate_templatefile_name"));
             $this->setCommonData();
             return false;
         }
     }
     $sourceFile = $templateFolder . $this->_fileId;
     $newFile = $templateFolder . $this->_newFileId;
     if (!File::copy($sourceFile, $newFile)) {
         if (empty($this->_subFolderId)) {
             $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
         } else {
             $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
         }
         $this->_view->setErrorMessage($this->_locale->tr("error_copying_templatefile"));
         $this->setCommonData();
         return false;
     }
     // if everything went ok...
     $this->_session->setValue("blogInfo", $this->_blogInfo);
     $this->saveSession();
     if (empty($this->_subFolderId)) {
         $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
     } else {
         $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
     }
     $this->_view->setSuccessMessage($this->_locale->tr("templateeditor_templatefile_copyed_ok"));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     return true;
 }
 /**
  * Creates a new project using the input from the form
  *
  * @param CreateProjectRequest $request The validated request
  * @return mixed
  */
 public function create(CreateProjectRequest $request)
 {
     $newEntry = Project::create(['author' => Auth::user()->username, 'user_id' => Auth::user()->id, 'title' => $request->getTitle(), 'description' => $request->getDescription(), 'body' => $request->getBody(), 'statement_title' => 'Mission Statement', 'statement_body' => 'This is where you write about your mission statement or make it whatever you want.', 'tab_title' => 'Welcome', 'tab_body' => 'Here you can write a message or maybe the status of your project for all your members to see.']);
     $thumbnail = $request->file('thumbnail');
     $thumbnail->move(base_path() . '/public/images/projects', 'product' . $newEntry->id . '.jpg');
     //Sets banner image to a random pre-made banner
     $images = glob(base_path() . "/public/images/banners/*");
     $imagePath = base_path() . '/public/images/projects/' . 'banner' . $newEntry->id . '.jpg';
     $rand = random_int(0, count($images) - 1);
     \File::copy($images[$rand], $imagePath);
     //Add creator as a member and make admin of the project
     $newEntry->addMember(true);
     //Add creator as a follower of the project
     $newEntry->addFollower();
     return redirect('/project/' . $newEntry->title);
 }
Example #26
0
 /**
  * Creates project comments, users, and projects all in one
  *
  * @return void
  */
 public function run()
 {
     $dir = "public/images/seeds/";
     $images = glob($dir . "*");
     $faker = Faker\Factory::create();
     for ($i = 0, $j = 0; $i < 10; $i++, $j++) {
         factory(ProjectComment::class, 'selfContained', 1)->create();
         $newestID = DB::table('projects')->orderBy('created_at', 'desc')->first()->id;
         //Get the project that was just created's id
         $imagePath = 'public/images/projects/' . 'product' . $newestID . '.jpg';
         if (sizeof($images) <= $j) {
             $j = 0;
         }
         File::copy($images[$j], $imagePath);
     }
 }
Example #27
0
 public function insert($imageList, $galleryID, $data)
 {
     $db = MySQL::getInstance();
     $db->query("SELECT COUNT(*) FROM `gallery_image` WHERE `GalleryID` = " . $db->escape((int) $galleryID));
     $row = $db->fetchField();
     $position = $row ? $row : 0;
     $position = $row = $db->fetchField() ? $row : 0;
     foreach ($imageList as $key => $image) {
         $position++;
         $db->query("INSERT INTO gallery_image (GalleryID, `File`, `Title`, `Description`, `Position`) VALUES (\n\t\t\t\t" . $db->escape((int) $galleryID) . ",\n\t\t\t\t" . $db->escape($image) . ",\n\t\t\t\t" . $db->escape($data['Title'][$key], 255) . ",\t\t\t\t\n\t\t\t\t" . $db->escape($data['Description'][$key]) . ",\t\t\t\t\n\t\t\t\t" . $db->escape((int) $position) . "\n\t\t\t)");
         if (File::copy($image, 'thumb_' . $image, 'var/gallery/')) {
             File::imageCrop('thumb_' . $image, 'var/gallery/', 155, 110);
         }
         File::imageResize($image, 'var/gallery/');
     }
 }
Example #28
0
 /**
  * Create a clone for Reflection
  * Allows reflecting the same class as its modified
  *
  * @return string New class name
  */
 protected function _createClone()
 {
     if (!isset($this->_File) || !isset($this->class)) {
         return false;
     }
     $class = uniqid($this->class);
     $clone = dirname($this->_File->path) . DS . $class . '.php';
     $this->_File->copy($clone);
     $file = new File($clone);
     $contents = $file->read();
     $contents = str_ireplace('class ' . $this->class, 'class ' . $class, $contents);
     $file->write($contents);
     $file->close();
     $this->_Clones[] = $clone;
     return $class;
 }
Example #29
0
 protected function migrations()
 {
     $this->info('Creating migration!');
     $files = \File::files($this->laravel['path.database'] . '/migrations');
     foreach ($files as $file) {
         if (ends_with((string) $file, '_cms_core_tables.php')) {
             throw new \Exception("You could have a similar migration on {$file}!");
         }
     }
     $path = $this->laravel['path.database'] . '/migrations/' . date('Y_m_d_His') . '_cms_core_tables.php';
     $stub = __DIR__ . '/../stubs/core.stub';
     if (!\File::copy($stub, $path)) {
         throw new \Exception('We could not create the migration!');
     }
     $this->info('Run migration!');
     Artisan::call('migrate');
 }
 public function testWrite()
 {
     $file = new File('/tmp/test');
     $this->assertEquals(true, $file->append("test\n"));
     $this->assertEquals(true, $file->append("test\n"));
     $this->assertEquals(true, $file->copy('/tmp/test2'));
     $this->assertEquals(true, $file->delete());
     $file = new File('/tmp/test2');
     $linecount = 0;
     foreach ($file->lines() as $line) {
         $linecount = $linecount + 1;
     }
     $array = $file->toArray();
     $this->assertEquals(2, count($array));
     $this->assertEquals(2, $linecount);
     $this->assertEquals(true, $file->delete());
     $this->assertEquals(false, $file->isFile());
 }