Skip to content

Instantly share code, notes, and snippets.

@skrosoft
Created November 21, 2016 15:45
Show Gist options
  • Save skrosoft/b27d5f9eabeb27e1003e9aa3223e02c3 to your computer and use it in GitHub Desktop.
Save skrosoft/b27d5f9eabeb27e1003e9aa3223e02c3 to your computer and use it in GitHub Desktop.
clone entity with file (assume upload function is called with lifecycle)
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