loading.............
Buenas colegas.
Intento obtener los headers de alguna imagen que el usuario va a subir con este simple código:
Código PHP:
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, "http://imgnook.com/fixed/437825/vegan-red-velvet-2-by-bittykate.jpg" );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_HEADER, true );
curl_setopt ( $ch, CURLOPT_NOBODY, true );
$data = curl_exec ( $ch );
print_r($data);
print_r(curl_getinfo($ch));
resultado:
Código:
HTTP/1.1 200 OK
Date: Mon, 01 Feb 2010 08:04:21 GMT
Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.9
Cache-Control: private, max-age=10800, pre-check=10800
Pragma: private
Expires: Sat, 24 Apr 10 02:04:21 -0500
Accept-Ranges: bytes
Set-Cookie: PHPSESSID=a7363187375d07980483f8b08b5736ea; path=/
Set-Cookie: sess=ba2fd310dcaa8781a9a652a31baf3c68; expires=Mon, 01-Feb-2010 09:04:21 GMT; path=/; domain=.imgnook.com
Set-Cookie: sess=ba2fd310dcaa8781a9a652a31baf3c68; expires=Mon, 01-Feb-2010 09:04:21 GMT; path=/; domain=.imgnook.com
Content-Range: bytes 0-103849/103850
Content-Length: 103850
Content-Type: image/jpeg
Array
(
[url] => http://imgnook.com/fixed/437825/vegan-red-velvet-2-by-bittykate.jpg
[content_type] => image/jpeg
[http_code] => 200
[header_size] => 741
[request_size] => 163
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.5
[namelookup_time] => 0
[connect_time] => 0.218
[pretransfer_time] => 0.218
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 103850
[upload_content_length] => -1
[starttransfer_time] => 0.5
[redirect_time] => 0
)
Con esto tengo los headers de la imagen y validar el tamaño del mismo para permitir a un usuario subirlo o no.
Ahora para que me encontrado con este tipo de imágenes:
Imagen_virtual. http://twitpic.com/show/large/10lugr.jpg
La URL hace redirección 302 al verdadero archivo:
Imagen_real. http://web2.twitpic.com/img/61485435...2a1-scaled.jpg
Por lo tanto mi codigo solo me devuelve el tamaño de la imagen virtual ( CERO o algunos bytes ) y si le pongo true a CURLOPT_FOLLOWLOCATION:
Código PHP:
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
Me sigue devolviendo el header de la imagen virtual.
No puedo seguir el Location: de la imagen virtual hacia la original ya que la original solo se muestra si se encuentra a imagen virtual como referer.
como pueden ver aca
Código PHP:
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, "http://web2.twitpic.com/img/61485435-c90f66b1200b346622830b281d8bc6de.4b6662a1-scaled.jpg" );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_HEADER, true );
curl_setopt ( $ch, CURLOPT_NOBODY, true );
$data = curl_exec ( $ch );
print_r($data);
print_r(curl_getinfo($ch));
resultado
Código:
HTTP/1.1 200 OK
Date: Mon, 01 Feb 2010 07:58:27 GMT
Server: Apache/2.2.11 (FreeBSD) mod_ssl/2.2.11 OpenSSL/0.9.8e DAV/2 PHP/5.2.9 with Suhosin-Patch
X-Powered-By: PHP/5.2.9
Content-Type: text/html
Array
(
[url] => http://web2.twitpic.com/img/61485435-c90f66b1200b346622830b281d8bc6de.4b6662a1-scaled.jpg
[content_type] => text/html
[http_code] => 200
[header_size] => 204
[request_size] => 185
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.485
[namelookup_time] => 0
[connect_time] => 0.235
[pretransfer_time] => 0.235
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0.485
[redirect_time] => 0
)
Pero lo he intentado de todos modos.
Código PHP:
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, "http://web2.twitpic.com/img/61485435-c90f66b1200b346622830b281d8bc6de.4b6662a1-scaled.jpg" );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt ( $ch, CURLOPT_REFERER, "http://twitpic.com/show/large/10lugr.jpg" );
curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_HEADER, true );
curl_setopt ( $ch, CURLOPT_NOBODY, true );
$data = curl_exec ( $ch );
print_r($data);
print_r(curl_getinfo($ch));
con el resultado
Código:
HTTP/1.1 200 OK
Date: Mon, 01 Feb 2010 07:56:05 GMT
Server: Apache/2.2.11 (FreeBSD) mod_ssl/2.2.11 OpenSSL/0.9.8e DAV/2 PHP/5.2.9 with Suhosin-Patch
X-Powered-By: PHP/5.2.9
Content-Type: image/jpeg
Array
(
[url] => http://web2.twitpic.com/img/61485435-c90f66b1200b346622830b281d8bc6de.4b6662a1-scaled.jpg
[content_type] => image/jpeg
[http_code] => 200
[header_size] => 205
[request_size] => 236
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.578
[namelookup_time] => 0
[connect_time] => 0.344
[pretransfer_time] => 0.344
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0.578
[redirect_time] => 0
)
No puedo cambiar
Código PHP:
curl_setopt ( $ch, CURLOPT_NOBODY, true );
a false o quitarlo, ya que estaría descargando toda la imagen solo para saber su tamaño (ni pensarlo).
Bueno.... ese es mi problema, espero alguien haya pasado por eso y solucionado hehehe.
Saludos!!
connection closed.