o curl trata o redirecionamento e baixa o arquivo, e vc pode ler o header
para pegar o mime do arquivo.

On Thu, Mar 22, 2012 at 10:53 AM, Anderson Marques Ferraz <
[email protected]> wrote:

> Cara, eu acessei o link e meu navegador baixou a imagem já com a extensão.
> *Acho* que você não precisa verificar o mime-type da imagem. Basta você
> examinar os headers da requisição HTTP, o que eu imagino que dá pra fazer
> com as funções da extensão php-curl.
>
> Na linha de comando, eu executei:
> *$ curl -v https://apis.live.net/v5.0/e60fd67ad25e5db5/picture*
>
> A saída foi:
> * About to connect() to apis.live.net port 443 (#0)
> *   Trying 64.4.45.31... connected
> * Connected to apis.live.net (64.4.45.31) port 443 (#0)
> * Initializing NSS with certpath: sql:/etc/pki/nssdb
> *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
>   CApath: none
> * SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
> * Server certificate:
> * subject: CN=apis.live.net
> * start date: Dez 08 19:19:41 2010 GMT
> * expire date: Dez 07 19:19:41 2012 GMT
> * common name: apis.live.net
> * issuer: CN=Microsoft Secure Server
> Authority,DC=redmond,DC=corp,DC=microsoft,DC=com
> > GET /v5.0/e60fd67ad25e5db5/picture HTTP/1.1
> > User-Agent: curl/7.21.7 (x86_64-redhat-linux-gnu) libcurl/7.21.7 NSS/
> 3.13.1.0 zlib/1.2.5 libidn/1.22 libssh2/1.2.7
> > Host: apis.live.net
> > Accept: */*
> >
> < HTTP/1.1 302 Found
> < Cache-Control: private, no-cache, no-store, must-revalidate
> < Content-Length: 0
> < Location: *
> http://blufiles.storage.msn.com/y1m96xi_KMcovyZHJqwzv79EOZ2PeBcMFAR_lTBflFzg6fXdg4PV3tUqhZGe4Mqmmq-rZ9ju61M-VajC6sc4ghqMQ
> *
> < Server: Live-API/16.2.1377.307 Microsoft-HTTPAPI/2.0
> < X-Content-Type-Options: nosniff
> < X-HTTP-Live-Request-Id: API.f3327e32-ae57-4650-8fe4-b71e5cc7c260
> < X-HTTP-Live-Server: BAYMSG1030140
> < Date: Thu, 22 Mar 2012 13:46:05 GMT
> <
> * Connection #0 to host apis.live.net left intact
> * Closing connection #0
>
>
>
>
> Como foi um status 302 (redirect), aí eu peguei o Location dele, em
> negrito, e re-executei o curl. A saída foi a seguinte (atente para o
> content-type):
>
>
> * About to connect() to blufiles.storage.msn.com port 80 (#0)
> *   Trying 65.55.254.44... connected
> * Connected to blufiles.storage.msn.com (65.55.254.44) port 80 (#0)
> > GET
> /y1m96xi_KMcovyZHJqwzv79EOZ2PeBcMFAR_lTBflFzg6fXdg4PV3tUqhZGe4Mqmmq-rZ9ju61M-VajC6sc4ghqMQ
> HTTP/1.1
> > User-Agent: curl/7.21.7 (x86_64-redhat-linux-gnu) libcurl/7.21.7 NSS/
> 3.13.1.0 zlib/1.2.5 libidn/1.22 libssh2/1.2.7
> > Host: blufiles.storage.msn.com
> > Accept: */*
> >
> < HTTP/1.1 200 OK
> < Cache-Control: private
> < Content-Length: 2945
> < *Content-Type: image/jpeg*
> < Content-Location:
> http://blufiles.storage.msn.com/y1m96xi_KMcovyZHJqwzv79EOZ2PeBcMFAR_lTBflFzg6fXdg4PV3tUqhZGe4Mqmmq-rZ9ju61M-VajC6sc4ghqMQ
> < Expires: Wed, 20 Jun 2012 13:49:58 GMT
> < Last-Modified: Wed, 29 Sep 2010 22:29:20 GMT
>  < P3P: CP="BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo"
> < X-MSNSERVER: BLU____2040226
> < X-SqlDataOrigin: S
> < X-StreamOrigin: MC
> < Content-Disposition: attachment;
> filename="y1m96xi_KMcovyZHJqwzv79EOZ2PeBcMFAR_lTBflFzg6fXdg4PV3tUqhZGe4Mqmmq-rZ9ju61M-VajC6sc4ghqMQ"
> < X-Content-Type-Options: nosniff
> < Date: Thu, 22 Mar 2012 13:49:57 GMT
> <
>
> (Aqui eu omiti o restante, que era a imagem em si)
>
> Também acho que esse link pode te ajudar fazer isso em PHP, mas não testei:
>
> http://stackoverflow.com/questions/1378915/header-only-retreival-in-php-via-curl
>
> --
> Anderson Marques Ferraz
> UEFS - Engenharia de Computação - 2006.1
> Linux user #500881 - http://counter.li.org/
>
> Money demands that you sell, not your weakness to men's stupidity, but
> your talent for their reason.
> (Francisco d'Anconia)
>
>  --
> Você está recebendo esta mensagem porque se inscreveu no grupo "Kohana
> Php" dos Grupos do Google.
> Para postar neste grupo, envie um e-mail para [email protected].
> Para cancelar a inscrição nesse grupo, envie um e-mail para
> [email protected].
> Para obter mais opções, visite esse grupo em
> http://groups.google.com/group/kohana-php?hl=pt-BR.
>



-- 
Vitor de Araujo Simões (Dalai/Snag)
Estudante de Ciências da Computação - USP

"Computation is the art of building solutions
- at the cost of creating more problems"


http://www.varaujo.com.br

-- 
Você está recebendo esta mensagem porque se inscreveu no grupo "Kohana Php" dos 
Grupos do Google.
Para postar neste grupo, envie um e-mail para [email protected].
Para cancelar a inscrição nesse grupo, envie um e-mail para 
[email protected].
Para obter mais opções, visite esse grupo em 
http://groups.google.com/group/kohana-php?hl=pt-BR.

Responder a