本文整理汇总了PHP中File::copy方法的典型用法代码示例。如果您正苦于以下问题:PHP File::copy方法的具体用法?PHP File::copy怎么用?PHP File::copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copyFile
protected function copyFile($file, $target)
{
if (!\File::exists($target)) {
return \File::copy($file, $target);
}
return false;
}
示例2: copyDir
/**
* Recursively copy a folder and its contents
* http://aidan.dotgeek.org/lib/?file=function.copyr.php
*
* @author Aidan Lister <aidan@php.net>
* @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;
}
示例3: copy
/**
* 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);
}
示例4: copy
/**
* 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;
}
示例5: execute
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;
}
示例6: copy
/**
* 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!
}
}
}
}
示例7: copy
/**
* 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;
}
示例8: replace
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()));
}
示例9: seed
/**
* 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);
}
示例10: copyFiles
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);
}
}
示例11: _createConfigFile
/**
* 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);
}
}
示例12: testRemoveFile
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));
}
示例13: main
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");
}
示例14: genFlapUpdateFile
/**
* 產生輔翼系統更新會員資料檔案
*
* @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;
}
示例15: getPicture
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);
}