This helped me with exif_imagetype as well. Thanks Oscar!
On Monday, June 15, 2015 at 12:50:08 PM UTC+5, Oscar Otero wrote:
>
> Well, I have found a solution using the metadata of the stream:
>
> $tmp_file = $upload->getStream()->getMetadata('uri’);
> $mime = finfo_file($finfo, $tmp_file);
>
> Thanks.
>
>
> El 15/6/2015, a las 4:01, Woody Gilk <[email protected] <javascript:>>
> escribió:
>
> I'm not sure about this, but can't you use the $context parameter, like
> so: finfo_file(NULL, $options, $upload->getStream()) ?
>
> http://php.net/manual/en/function.finfo-file.php
>
> On Sunday, June 14, 2015 at 12:59:34 PM UTC-5, Oscar Otero wrote:
>>
>> Sorry but this is not valid solution because:
>>
>> - finfo only has support for buffers (finfo_buffer) and filenames
>> (finfo_file) but not for stream resources
>> - on detach the resource, the stream (and uploadedFile instance) change
>> to an inusable state, so the file cannot be copied or moved after that.
>>
>> I only want to check the mime type of the file before move it.
>>
>>
>> El 14/6/2015, a las 19:39, Mengdi Gao <[email protected]> escribió:
>>
>> Try:
>>
>> $resource = $uploadedFile->getStream()->detach()
>>
>> On Mon, Jun 15, 2015 at 01:30 Oscar Otero <[email protected]> wrote:
>>
>>> Hi.
>>> I'm trying to port some of my libraries to be compatible with psr-7 but
>>> I found a problem in the spec.
>>>
>>> Form-manager is a simple library to manage forms in php. It provides php
>>> implementations to some html validation atributes such "required",
>>> "pattern", "min", "max", etc.
>>>
>>> File inputs can have the "accept" attribute to limit the upload to some
>>> mime-types and, of course, there is a php implementation to ensure the
>>> uploaded files are right. You can see the implementation here:
>>>
>>> https://github.com/oscarotero/form-manager/blob/master/src/Validators/Accept.php#L18
>>>
>>> As you can see, I use the finfo extension of php to validate the file,
>>> because it's not recomended to use the client mime type. The problem is
>>> with the UploadedFileInterface I cannot access to the tmp_name of the file.
>>> A solution could be get the buffer of the file and use finfo-buffer
>>> <http://php.net/manual/en/function.finfo-buffer.php> but this cannot be
>>> done with large files.
>>>
>>> I think this interface needs a method like $file->getServerFilename().
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "PHP Framework Interoperability Group" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/php-fig/74729d87-e3a4-46e3-85a9-6088900d4290%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/php-fig/74729d87-e3a4-46e3-85a9-6088900d4290%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "PHP Framework Interoperability Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/php-fig/CAJ0PohPOKTj592OH-5tMs%3D24zOg7VCGUp-G9f1bWYyXuWFjwQw%40mail.gmail.com
>>
>> <https://groups.google.com/d/msgid/php-fig/CAJ0PohPOKTj592OH-5tMs%3D24zOg7VCGUp-G9f1bWYyXuWFjwQw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "PHP Framework Interoperability Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/php-fig/97b67785-9305-4653-b205-93ad438f5bf0%40googlegroups.com
>
> <https://groups.google.com/d/msgid/php-fig/97b67785-9305-4653-b205-93ad438f5bf0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
You received this message because you are subscribed to the Google Groups "PHP
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/php-fig/9a8c0a65-8000-4bc9-9ff1-a41fa43792a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.