I have a pretty good Symfony function that makes some file operations from a posted form (generated on symfony), the input of this function is a UploadedFile Object and an example of this object (print_r) is:
Symfony\Component\HttpFoundation\File\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => Untitled-10001.png
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/png
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 8718
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[pathName:SplFileInfo:private] => /tmp/phpduxlg4
[fileName:SplFileInfo:private] => phpduxlg4
)
I have another web form, pure html with no Symfony implementations or integration. So the posted file from a form like this one as you know will have this form (print_r):
Array
(
[gifts_add] => Array
(
[name] => Array
(
[image] => Untitled-10001.png
)
[type] => Array
(
[image] => image/png
)
[tmp_name] => Array
(
[image] => /tmp/phpduxlg4
)
[error] => Array
(
[image] => 0
)
[size] => Array
(
[image] => 8718
)
)
)
I cant modify the function that handles the file, so I need a way to "transform" the normal upload file object fron the example two into the Symfony uploadFile object from the first one.
I know is a hack so not a very clean solution, but at the moment is my only way of solving this, so in resume, if you have an object like the second one, how you make it to look like the first one?
EDIT:
Based on the answers this is what i got so far:
print_r($_FILES);
print_r($gift->getImage( ));
echo '---';
$myfile= new \Component\HttpFoundation\File\UploadedFile();
$myfile->setOriginalName($_FILES["gifts_add"]["name"][0]);
$myfile->setMimeType($_FILES["gifts_add"]["type"][0]);
$myfile->setSize($_FILES["gifts_add"]["size"][0]);
$myfile->setError($_FILES["gifts_add"]["error"][0]);
$myfile->setPathName($_FILES["gifts_add"]["tmp_name"][0]);
$myfile->setFileName($_FILES["gifts_add"]["name"][0]);
print_r($myfile);
die('DEBUG');
Still the print_r($myfile) seems to output empty or to block the script.