Created
November 21, 2016 15:45
-
-
Save skrosoft/b27d5f9eabeb27e1003e9aa3223e02c3 to your computer and use it in GitHub Desktop.
clone entity with file (assume upload function is called with lifecycle)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function __clone() { | |
$this->id = null; | |
if (!is_null($this->filename)){ | |
$temp_file = tempnam(ini_get('upload_tmp_dir'), sha1(uniqid(mt_rand(), true))); | |
$file = new File($this->getAbsolutePath()); | |
copy($this->getAbsolutePath(), $temp_file); | |
$up_file = new UploadedFile($temp_file, $this->filename, $file->getMimeType(), $file->getSize(), UPLOAD_ERR_OK, true); | |
$this->setFile($up_file); | |
} | |
unset($this->_entityPersister, $this->_identifier); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment