ZF2 Import and validate external pictures from URLs?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

ZF2 Import and validate external pictures from URLs?

cmple
Hi,

How can I upload images to the server from an external URL (e.g.: https://alphalister.com/files/cmple_35e2/i/m/e0d215f9a9f0399f2f0dff192ed0ffba.jpg) and validate it using the existing Validators (e.g.: "ImageSize")

I've been using Zend\File\Transfer\Transfer for uploading images to the server (user->server).
With the Transfer class I can easily set image Validators...
for example:
$transfer->addValidators(array(
        array('ImageSize', true,
                                array(
                                        'minwidth' => 100,
                                        'minheight' => 100,
                                        'maxwidth' => 5000,
                                        'maxheight' => 500,
                                ),
                        ),
));


Thank You!
Roman.





Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Import and validate external pictures from URLs?

Alejandro Celaya
You could download the image using Zend's http client and then apply
validators to it without using the Transfer object.
If the image is not valid you can delete it and display an error.
However, you will have to think how to deal with too big files and invalid
URLs.
El 26/5/2015 4:59, "cmple" <[hidden email]> escribió:

> Hi,
>
> How can I upload images to the server from an external URL (e.g.:
>
> https://alphalister.com/files/cmple_35e2/i/m/e0d215f9a9f0399f2f0dff192ed0ffba.jpg
> )
> and validate it using the existing Validators (e.g.: "ImageSize")
>
> I've been using Zend\File\Transfer\Transfer for uploading images to the
> server (user->server).
> With the Transfer class I can easily set image Validators...
> for example:
> $transfer->addValidators(array(
>         array('ImageSize', true,
>                                 array(
>                                         'minwidth' => 100,
>                                         'minheight' => 100,
>                                         'maxwidth' => 5000,
>                                         'maxheight' => 500,
>                                 ),
>                         ),
> ));
>
>
> Thank You!
> Roman.
>
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Import and validate external pictures from URLs?

Alejandro Celaya
In reply to this post by cmple
You could download the image using Zend's http client and then apply
validators to it without using the Transfer object.
If the image is not valid you can delete it and display an error.
However, you will have to think how to deal with too big files and invalid
URLs.
El 26/5/2015 4:59, "cmple" <[hidden email]> escribió:

> Hi,
>
> How can I upload images to the server from an external URL (e.g.:
>
> https://alphalister.com/files/cmple_35e2/i/m/e0d215f9a9f0399f2f0dff192ed0ffba.jpg
> )
> and validate it using the existing Validators (e.g.: "ImageSize")
>
> I've been using Zend\File\Transfer\Transfer for uploading images to the
> server (user->server).
> With the Transfer class I can easily set image Validators...
> for example:
> $transfer->addValidators(array(
>         array('ImageSize', true,
>                                 array(
>                                         'minwidth' => 100,
>                                         'minheight' => 100,
>                                         'maxwidth' => 5000,
>                                         'maxheight' => 500,
>                                 ),
>                         ),
> ));
>
>
> Thank You!
> Roman.
>
>
>
>
>
>
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Import and validate external pictures from URLs?

cmple
Hey Alejandro,
Thanks for your reply!
I have one more question, how can I apply the file Validation without using the global $_FILES[] variable?

for example:
$validator = new Validator\IsImage();
$valid = $validator->isValid();

Thanks!
Roman.
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Import and validate external pictures from URLs?

latterd
Hi,

You can find out file information using:
http://php.net/manual/en/function.finfo-file.php

Also, a common way is to use getimagesize() function, if it throws an error
or returns false its not an image.

I think it is a 2 step process, first you get the image from the url,
validate etc.

Then upload/send to your server.



On 26 May 2015 at 17:05, cmple <[hidden email]> wrote:

> Hey Alejandro,
> Thanks for your reply!
> I have one more question, how can I apply the file Validation without using
> the global $_FILES[] variable?
>
> for example:
> $validator = new Validator\IsImage();
> $valid = $validator->isValid();
>
> Thanks!
> Roman.
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542p4662545.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Import and validate external pictures from URLs?

cmple
Hi latterd,
for my existing image upload validation I'm using multiple zf validators with custom error messages:

array('Extension', true, array(
        'extension' => explode(',', $this->config->valid_upload_types),
        'messages' => array(
                'fileExtensionFalse' => 'Invalid picture type'
        )
)),
array('IsImage', true, array(
        'magicFile' => false,
)),
array('Size', true, array(
        'max' => $this->config->max_upload_size,
        'messages' => array(
                'fileSizeTooBig' => 'Picture size is too big'
        ),
)),
array('ImageSize', true,
        array(
                'minwidth' => $minSize->minwidth,
                'minheight' => $minSize->minheight,
                'maxwidth' => $this->config->max_width,
                'maxheight' => $this->config->max_height,
                'messages' => array(
                        'fileImageSizeHeightTooBig' => 'Picture height is too big',
                        'fileImageSizeWidthTooBig' => 'Picture width is too big',
                ),
        ),
),

are you suggesting that there is no way around this but only to create custom validations such as the use of the getimagesize() function?

also is it possible to use getimagesize() before uploading the image to the server (even to the /tmp folder)?

Thank You!
Roman.


latterd wrote
Hi,

You can find out file information using:
http://php.net/manual/en/function.finfo-file.php

Also, a common way is to use getimagesize() function, if it throws an error
or returns false its not an image.

I think it is a 2 step process, first you get the image from the url,
validate etc.

Then upload/send to your server.



On 26 May 2015 at 17:05, cmple <[hidden email]> wrote:

> Hey Alejandro,
> Thanks for your reply!
> I have one more question, how can I apply the file Validation without using
> the global $_FILES[] variable?
>
> for example:
> $validator = new Validator\IsImage();
> $valid = $validator->isValid();
>
> Thanks!
> Roman.
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542p4662545.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Import and validate external pictures from URLs?

latterd
Hi,

My assumption is that you want to upload a file, perform validation on it,
then upload to another server?

So the first step is to get the file, via the validators you mentioned.

After that you have the file on disk, validated.

Now all that is left to do is put/upload/copy/post the file to the server
you want.

Does that help :)




On 26 May 2015 at 21:09, cmple <[hidden email]> wrote:

> Hi latterd,
> for my existing image upload validation I'm using multiple zf validators
> with custom error messages:
>
> array('Extension', true, array(
>         'extension' => explode(',', $this->config->valid_upload_types),
>         'messages' => array(
>                 'fileExtensionFalse' => 'Invalid picture type'
>         )
> )),
> array('IsImage', true, array(
>         'magicFile' => false,
> )),
> array('Size', true, array(
>         'max' => $this->config->max_upload_size,
>         'messages' => array(
>                 'fileSizeTooBig' => 'Picture size is too big'
>         ),
> )),
> array('ImageSize', true,
>         array(
>                 'minwidth' => $minSize->minwidth,
>                 'minheight' => $minSize->minheight,
>                 'maxwidth' => $this->config->max_width,
>                 'maxheight' => $this->config->max_height,
>                 'messages' => array(
>                         'fileImageSizeHeightTooBig' => 'Picture height is
> too big',
>                         'fileImageSizeWidthTooBig' => 'Picture width is
> too big',
>                 ),
>         ),
> ),
>
> are you suggesting that there is no way around this but only to create
> custom validations such as the use of the getimagesize() function?
>
> also is it possible to use getimagesize() before uploading the image to the
> server (even to the /tmp folder)?
>
> Thank You!
> Roman.
>
>
>
> latterd wrote
> > Hi,
> >
> > You can find out file information using:
> > http://php.net/manual/en/function.finfo-file.php
> >
> > Also, a common way is to use getimagesize() function, if it throws an
> > error
> > or returns false its not an image.
> >
> > I think it is a 2 step process, first you get the image from the url,
> > validate etc.
> >
> > Then upload/send to your server.
> >
> >
> >
> > On 26 May 2015 at 17:05, cmple &lt;
>
> > roman.vidyayev@
>
> > &gt; wrote:
> >
> >> Hey Alejandro,
> >> Thanks for your reply!
> >> I have one more question, how can I apply the file Validation without
> >> using
> >> the global $_FILES[] variable?
> >>
> >> for example:
> >> $validator = new Validator\IsImage();
> >> $valid = $validator->isValid();
> >>
> >> Thanks!
> >> Roman.
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542p4662545.html
> >> Sent from the Zend Framework mailing list archive at Nabble.com.
> >>
> >> --
> >> List:
>
> > fw-general@.zend
>
> >> Info: http://framework.zend.com/archives
> >> Unsubscribe:
>
> > fw-general-unsubscribe@.zend
>
> >>
> >>
> >>
>
>
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542p4662547.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Import and validate external pictures from URLs?

jeremiah
You can't trust it of course, but the client can do some convenience validation before the upload. See the Blue Imp file upload package.

Jeremiah

> On May 26, 2015, at 1:41 PM, Daniel Latter <[hidden email]> wrote:
>
> Hi,
>
> My assumption is that you want to upload a file, perform validation on it,
> then upload to another server?
>
> So the first step is to get the file, via the validators you mentioned.
>
> After that you have the file on disk, validated.
>
> Now all that is left to do is put/upload/copy/post the file to the server
> you want.
>
> Does that help :)
>
>
>
>
>> On 26 May 2015 at 21:09, cmple <[hidden email]> wrote:
>>
>> Hi latterd,
>> for my existing image upload validation I'm using multiple zf validators
>> with custom error messages:
>>
>> array('Extension', true, array(
>>        'extension' => explode(',', $this->config->valid_upload_types),
>>        'messages' => array(
>>                'fileExtensionFalse' => 'Invalid picture type'
>>        )
>> )),
>> array('IsImage', true, array(
>>        'magicFile' => false,
>> )),
>> array('Size', true, array(
>>        'max' => $this->config->max_upload_size,
>>        'messages' => array(
>>                'fileSizeTooBig' => 'Picture size is too big'
>>        ),
>> )),
>> array('ImageSize', true,
>>        array(
>>                'minwidth' => $minSize->minwidth,
>>                'minheight' => $minSize->minheight,
>>                'maxwidth' => $this->config->max_width,
>>                'maxheight' => $this->config->max_height,
>>                'messages' => array(
>>                        'fileImageSizeHeightTooBig' => 'Picture height is
>> too big',
>>                        'fileImageSizeWidthTooBig' => 'Picture width is
>> too big',
>>                ),
>>        ),
>> ),
>>
>> are you suggesting that there is no way around this but only to create
>> custom validations such as the use of the getimagesize() function?
>>
>> also is it possible to use getimagesize() before uploading the image to the
>> server (even to the /tmp folder)?
>>
>> Thank You!
>> Roman.
>>
>>
>>
>> latterd wrote
>>> Hi,
>>>
>>> You can find out file information using:
>>> http://php.net/manual/en/function.finfo-file.php
>>>
>>> Also, a common way is to use getimagesize() function, if it throws an
>>> error
>>> or returns false its not an image.
>>>
>>> I think it is a 2 step process, first you get the image from the url,
>>> validate etc.
>>>
>>> Then upload/send to your server.
>>>
>>>
>>>
>>> On 26 May 2015 at 17:05, cmple &lt;
>>
>>> roman.vidyayev@
>>
>>> &gt; wrote:
>>>
>>>> Hey Alejandro,
>>>> Thanks for your reply!
>>>> I have one more question, how can I apply the file Validation without
>>>> using
>>>> the global $_FILES[] variable?
>>>>
>>>> for example:
>>>> $validator = new Validator\IsImage();
>>>> $valid = $validator->isValid();
>>>>
>>>> Thanks!
>>>> Roman.
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542p4662545.html
>>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>>
>>>> --
>>>> List:
>>
>>> fw-general@.zend
>>
>>>> Info: http://framework.zend.com/archives
>>>> Unsubscribe:
>>
>>> fw-general-unsubscribe@.zend
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542p4662547.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>> --
>> List: [hidden email]
>> Info: http://framework.zend.com/archives
>> Unsubscribe: [hidden email]
>>
>>
>>

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: ZF2 Import and validate external pictures from URLs?

cmple
In reply to this post by latterd
Hi latterd,

my plan is to write the file directly to the server from an external URL (not from the user upload).
For example copy('https://alphalister.com/files/cmple_35e2/i/m/e0d215f9a9f0399f2f0dff192ed0ffba.jpg', '/server/files/location/e0d215f9a9f0399f2f0dff192ed0ffba.jpg');
Then be able to use the existing zf validators on that new file (if failed validation delete it) all of this will be done on the backend.

Whenever I try to use the zf validator independently of the zf-form upload, it always returns false.

$validator = new Validator\Extension(array(
                                'extension' => explode(',', $this->config->valid_upload_types),
                                'messages' => array(
                                        'fileExtensionFalse' => 'Invalid picture type'
                        )));
$isValid = $validator->isValid();


I can't figure out a way to inject actual file names into the validator...
For example:

$isValid = $validator->isValid(array('/server/files/location/e0d215f9a9f0399f2f0dff192ed0ffba.jpg'));

this also returns false

Thank You!!
Roman.

latterd wrote
Hi,

My assumption is that you want to upload a file, perform validation on it,
then upload to another server?

So the first step is to get the file, via the validators you mentioned.

After that you have the file on disk, validated.

Now all that is left to do is put/upload/copy/post the file to the server
you want.

Does that help :)




On 26 May 2015 at 21:09, cmple <[hidden email]> wrote:

> Hi latterd,
> for my existing image upload validation I'm using multiple zf validators
> with custom error messages:
>
> array('Extension', true, array(
>         'extension' => explode(',', $this->config->valid_upload_types),
>         'messages' => array(
>                 'fileExtensionFalse' => 'Invalid picture type'
>         )
> )),
> array('IsImage', true, array(
>         'magicFile' => false,
> )),
> array('Size', true, array(
>         'max' => $this->config->max_upload_size,
>         'messages' => array(
>                 'fileSizeTooBig' => 'Picture size is too big'
>         ),
> )),
> array('ImageSize', true,
>         array(
>                 'minwidth' => $minSize->minwidth,
>                 'minheight' => $minSize->minheight,
>                 'maxwidth' => $this->config->max_width,
>                 'maxheight' => $this->config->max_height,
>                 'messages' => array(
>                         'fileImageSizeHeightTooBig' => 'Picture height is
> too big',
>                         'fileImageSizeWidthTooBig' => 'Picture width is
> too big',
>                 ),
>         ),
> ),
>
> are you suggesting that there is no way around this but only to create
> custom validations such as the use of the getimagesize() function?
>
> also is it possible to use getimagesize() before uploading the image to the
> server (even to the /tmp folder)?
>
> Thank You!
> Roman.
>
>
>
> latterd wrote
> > Hi,
> >
> > You can find out file information using:
> > http://php.net/manual/en/function.finfo-file.php
> >
> > Also, a common way is to use getimagesize() function, if it throws an
> > error
> > or returns false its not an image.
> >
> > I think it is a 2 step process, first you get the image from the url,
> > validate etc.
> >
> > Then upload/send to your server.
> >
> >
> >
> > On 26 May 2015 at 17:05, cmple <
>
> > roman.vidyayev@
>
> > > wrote:
> >
> >> Hey Alejandro,
> >> Thanks for your reply!
> >> I have one more question, how can I apply the file Validation without
> >> using
> >> the global $_FILES[] variable?
> >>
> >> for example:
> >> $validator = new Validator\IsImage();
> >> $valid = $validator->isValid();
> >>
> >> Thanks!
> >> Roman.
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542p4662545.html
> >> Sent from the Zend Framework mailing list archive at Nabble.com.
> >>
> >> --
> >> List:
>
> > fw-general@.zend
>
> >> Info: http://framework.zend.com/archives
> >> Unsubscribe:
>
> > fw-general-unsubscribe@.zend
>
> >>
> >>
> >>
>
>
>
>
>
> --
> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/ZF2-Import-and-validate-external-pictures-from-URLs-tp4662542p4662547.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>