3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $string = '$file%s = $entity->getForm%s(); if ($file%s) { $filename%s = uniqid() . \'.\' . $file%s->getClientOriginalExtension(); $this->filesystem->write($filename%s, file_get_contents($file%s->getPathname())); $entity->set%s(\'/imgs/upload/service/\' . $filename%s); }'; $elements = array( '1' => 'Photo', '2' => 'Icon', '3' => 'TopPhoto', '4' => 'DescriptionPhoto', '5' => 'BenefitPhoto', '6' => 'IndicationPhoto', '7' => 'PreparationPhoto', ); foreach ($elements as $key => $element) { echo sprintf($string, $key, $element, $key, $key, $key, $key, $key, $element, $key)."\n"."\n"; }
Output for 4.3.0 - 7.2.0
$file1 = $entity->getFormPhoto(); if ($file1) { $filename1 = uniqid() . '.' . $file1->getClientOriginalExtension(); $this->filesystem->write($filename1, file_get_contents($file1->getPathname())); $entity->setPhoto('/imgs/upload/service/' . $filename1); } $file2 = $entity->getFormIcon(); if ($file2) { $filename2 = uniqid() . '.' . $file2->getClientOriginalExtension(); $this->filesystem->write($filename2, file_get_contents($file2->getPathname())); $entity->setIcon('/imgs/upload/service/' . $filename2); } $file3 = $entity->getFormTopPhoto(); if ($file3) { $filename3 = uniqid() . '.' . $file3->getClientOriginalExtension(); $this->filesystem->write($filename3, file_get_contents($file3->getPathname())); $entity->setTopPhoto('/imgs/upload/service/' . $filename3); } $file4 = $entity->getFormDescriptionPhoto(); if ($file4) { $filename4 = uniqid() . '.' . $file4->getClientOriginalExtension(); $this->filesystem->write($filename4, file_get_contents($file4->getPathname())); $entity->setDescriptionPhoto('/imgs/upload/service/' . $filename4); } $file5 = $entity->getFormBenefitPhoto(); if ($file5) { $filename5 = uniqid() . '.' . $file5->getClientOriginalExtension(); $this->filesystem->write($filename5, file_get_contents($file5->getPathname())); $entity->setBenefitPhoto('/imgs/upload/service/' . $filename5); } $file6 = $entity->getFormIndicationPhoto(); if ($file6) { $filename6 = uniqid() . '.' . $file6->getClientOriginalExtension(); $this->filesystem->write($filename6, file_get_contents($file6->getPathname())); $entity->setIndicationPhoto('/imgs/upload/service/' . $filename6); } $file7 = $entity->getFormPreparationPhoto(); if ($file7) { $filename7 = uniqid() . '.' . $file7->getClientOriginalExtension(); $this->filesystem->write($filename7, file_get_contents($file7->getPathname())); $entity->setPreparationPhoto('/imgs/upload/service/' . $filename7); }